Skip to content

Commit

Permalink
Merge aafd851 into 14c98f9
Browse files Browse the repository at this point in the history
  • Loading branch information
gnulnx committed Nov 9, 2016
2 parents 14c98f9 + aafd851 commit 45958ac
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion mongolog/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
logger = logging.getLogger('')
console = logging.getLogger('mongolog-int')

# The requset logger is turned of during http requests to avoid circular logic
request_logger = logging.getLogger("requests")

uuid_namespace = uuid.UUID('8296424f-28b7-5982-a434-e6ec8ef529b3')


Expand Down Expand Up @@ -473,6 +476,8 @@ def emit(self, record):
From python: type(record) == LogRecord
https://github.com/certik/python-2.7/blob/master/Lib/logging/__init__.py#L230
"""
# Disable the request logger
request_logger.disabled = False
log_record = self.create_log_record(record)

# TODO move this to a validate log_record method and add more validation
Expand All @@ -483,10 +488,13 @@ def emit(self, record):
customer_id = self.client_auth.split("/")[-2]
log_record['customer_id'] = customer_id

r = requests.post(self.client_auth, json=json.dumps(log_record, default=str), timeout=self.timeout, proxies={'http':''}) # noqa
r = requests.post(self.client_auth, json=json.dumps(log_record, default=str), timeout=self.timeout, proxies={'http': ''}) # noqa
# uncomment to debug
try:
print("Response:", json.dumps(r.json(), indent=4, sort_keys=True, default=str))
except ValueError as e:
if "No JSON object could be decoded" in str(e):
print("log write failed: ", r)

# Renable the requests logger
request_logger.disabled = True

0 comments on commit 45958ac

Please sign in to comment.