Skip to content

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

@diox

Description

@diox

JsonLogFormatter does:

# If there is an error, format it for nice output.
if record.exc_info is not None:
fields["error"] = repr(record.exc_info[1])
fields["traceback"] = safer_format_traceback(*record.exc_info)

However, python logging docs say:

If exc_info does not evaluate as false, it causes exception information to be added to the logging message. If an exception tuple (in the format returned by sys.exc_info()) or an exception instance is provided, it is used; otherwise, sys.exc_info() is called to get the exception information.

The difference is notable, because there is code out there that calls log.something(..., exc_info=False). In AMO, which has a logger inheriting from JsonLogFormatter, that causes the following traceback:

  File "/usr/local/lib/python3.6/logging/__init__.py", line 994, in emit
    msg = self.format(record)
  File "/usr/local/lib/python3.6/logging/__init__.py", line 840, in format
    return fmt.format(record)
  File "/deps/lib/python3.6/site-packages/dockerflow/logging.py", line 138, in format
    out = self.convert_record(record)
  File "/code/src/olympia/core/logger.py", line 58, in convert_record
    out = super().convert_record(record)
  File "/deps/lib/python3.6/site-packages/dockerflow/logging.py", line 127, in convert_record
    fields["error"] = repr(record.exc_info[1])
TypeError: 'bool' object is not subscriptable

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions