New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix message formatting while handling exceptions #76
Fix message formatting while handling exceptions #76
Conversation
Consider the following format: ``` LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'logzioFormat': { 'format': '{"additional_field": "value"}', 'validate': False } }, 'handlers': { 'logzio': { 'class': 'logzio.handler.LogzioHandler', 'level': 'INFO', 'formatter': 'logzioFormat', 'token': '<<LOGZIO-TOKEN>>', 'logzio_type': 'python-handler', 'logs_drain_timeout': 5, 'url': 'https://<<LOGZIO-URL>>:8071', 'retries_no': 4, 'retry_timeout': 2, } }, 'loggers': { '': { 'level': 'DEBUG', 'handlers': ['logzio'], 'propagate': True } } } ``` And the case, where the user logs an exception: ``` logger.exception("Something") ``` Python appends the exception traceback to the formatted message (`{"additional_field": "value"}` originally). Which would result in the logzio handler not being able to parse it as JSON, and thus not adding the additional fields to the log.
90287ab
to
489f90b
Compare
Encountered the same issue. Would be very helpful if this will be merged. |
logzio/handler.py
Outdated
@@ -79,6 +79,8 @@ def flush(self): | |||
def format(self, record): | |||
message = super(LogzioHandler, self).format(record) | |||
try: | |||
if record.exc_info: | |||
message = message.split("\nTraceback")[0] # only keep the original formatted message part |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for reporting this issue.
When I tried recreating with the example you provided, the field message looks like this:
'{"additional_field": "value"}\nNoneType: None'
So this line doesn't fix it for me.
What about message = message.split("\n")[0]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for reporting this issue. When I tried recreating with the example you provided, the field message looks like this:
'{"additional_field": "value"}\nNoneType: None'
So this line doesn't fix it for me. What aboutmessage = message.split("\n")[0]
?
I agree with @mirii1994 's proposed change. Would it be possible to expedite this? Happy to take over if needed!
Consider the following format:
And the case, where the user logs an exception:
Python appends the exception traceback to the formatted message (
{"additional_field": "value"}
originally). Which would result in the logzio handler not being able to parse it as JSON, and thus not adding the additional fields to the log.