Include exception stack trace in 'message'#131
Merged
arcivanov merged 1 commit intofluent:masterfrom Apr 11, 2018
Merged
Conversation
Brings fluent logging more inline with normal log formatters. Utilize logging.Formatter.format() which combines record.msg with the exc_text. Signed-off-by: John Paulett <john@paulett.org>
8d7fb15 to
39e60c0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem: Since switching from the builtin log handlers to fluent-logger-python, when an exception occurs in my web application, I only receive the single line from
LogRecord.msg(e.g.{"message": "Internal Server Error: /"). The traceback and root exception are not present, making debugging nearly impossible.Solution: In this PR, when we do not have a dict or JSON message, instead of using
LogRecord.msgwe calllogging.Formatter.format(). For existing debug/info/warn/error string messages, this will result in no change, but when there is an exception, it will include theexc_textin the message, as is common with the builtin logging Formatters. For example:{'message': 'it failed\nTraceback (most recent call last):\n File "[..]/fluent-logger-python/tests/test_handler.py", line 363, in test_exception_message\n raise Exception(\'sample exception\')\nException: sample exception'}Alternative Solutions:
'stack_trace': '%(exc_text)s'. The downside to this approach is that 1) the majority of log statements which lack an exception will have an unnecessary"stack_trace": "None", 2) it is surprising behavior to new library users that the message does not include the normal trace info.