Handle exc_info=False in logging formatter#48
Handle exc_info=False in logging formatter#48jezdez merged 5 commits intomozilla-services:masterfrom
Conversation
https://docs.python.org/3/library/logging.html#logrecord-objects mentions exc_info should be a tuple or None, but False can be passed to a log statement according to https://docs.python.org/3/library/logging.html#logging.debug and when that happens, the exc_info on the LogRecord object *will* be False as well, so we need to handle that to avoid crashing.
|
|
||
| assert details["Severity"] == 3 | ||
| assert details["Fields"]["msg"] == "there was an error" | ||
| assert "error" not in details["Fields"] |
There was a problem hiding this comment.
This is causing a test error in Python 2, it seems that error and traceback are present, I'm not sure why. Any ideas of what to do here ? I haven't been dealing with Python 2 for a while now...
There was a problem hiding this comment.
Curious, can you check with PDB what exc_info is on Python 2.7? Does it evaluate differently on 2.x?
There was a problem hiding this comment.
- On python 3.8, when
exc_info=Falseis passed,record.exc_infoisFalse. - On python 2.7, when
exc_info=Falseis passed...record.exc_infois a tuple with the exception and the traceback anyway...
There was a problem hiding this comment.
Well, that is certainly disappointing, so as long as dockerflow supports Python 2, we should probably extend the condition so the tests pass.
There was a problem hiding this comment.
Could I just skip this test in python 2 ?
There was a problem hiding this comment.
Hmmyeah, how about we have a test for each Python version?
Codecov Report
@@ Coverage Diff @@
## master #48 +/- ##
=======================================
Coverage 98.80% 98.80%
=======================================
Files 19 19
Lines 587 587
Branches 79 79
=======================================
Hits 580 580
Misses 6 6
Partials 1 1
Continue to review full report at Codecov.
|
https://docs.python.org/3/library/logging.html#logrecord-objects mentions
exc_infoshould be a tuple orNone, butFalsecan be passed to a log statement according to https://docs.python.org/3/library/logging.html#logging.debug and when that happens, theexc_infoon theLogRecordobject will beFalseas well, so we need to handle that to avoid crashing.This isn't a theoretical case, there is code in the wild using
exc_info=Falseand that causes a crash with python-dockerflow logging.Fixes #46