Skip to content

Handle exc_info=False in logging formatter#48

Merged
jezdez merged 5 commits intomozilla-services:masterfrom
diox:exc_info_not_tuple
Jun 10, 2020
Merged

Handle exc_info=False in logging formatter#48
jezdez merged 5 commits intomozilla-services:masterfrom
diox:exc_info_not_tuple

Conversation

@diox
Copy link
Copy Markdown
Contributor

@diox diox commented Jun 9, 2020

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.

This isn't a theoretical case, there is code in the wild using exc_info=False and that causes a crash with python-dockerflow logging.

Fixes #46

diox added 2 commits June 9, 2020 13:36
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"]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, can you check with PDB what exc_info is on Python 2.7? Does it evaluate differently on 2.x?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • On python 3.8, when exc_info=False is passed, record.exc_info is False.
  • On python 2.7, when exc_info=False is passed... record.exc_info is a tuple with the exception and the traceback anyway...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that is certainly disappointing, so as long as dockerflow supports Python 2, we should probably extend the condition so the tests pass.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could I just skip this test in python 2 ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmyeah, how about we have a test for each Python version?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah let's do that. c650711

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jun 10, 2020

Codecov Report

Merging #48 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           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           
Impacted Files Coverage Δ
src/dockerflow/logging.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d7fadb7...1918423. Read the comment docs.

@jezdez jezdez merged commit b8f094b into mozilla-services:master Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deal with exc_info not being a tuple while not being None either in JsonLogFormatter

3 participants