Skip to content

Commit

Permalink
Check a dict passed to ProcessorFormatter actually came from structlog.
Browse files Browse the repository at this point in the history
ProcessorFormatter assumes certain attributes are attached by wrap_for_formatter
but originally only tested if it was receiving a dictionary as the log message.

This breaks if any libraries you use happen to pass dictionaries as log messages
expecting them to print using default string formatting.

Fortunately since the behavior of the LogRecord is different between the two
paths, we can resolve this by testing for the relevent attrs before choosing.
  • Loading branch information
wrouesnel committed Nov 23, 2018
1 parent 3147ea8 commit e9c3f08
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/structlog/stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def format(self, record):
# Make a shallow copy of the record to let other handlers/formatters
# process the original one
record = logging.makeLogRecord(record.__dict__)
if isinstance(record.msg, dict):
if isinstance(record.msg, dict) and hasattr(record,"_logger") and hasattr(record,"_name"):
# Both attached by wrap_for_formatter
logger = record._logger
meth_name = record._name
Expand Down

0 comments on commit e9c3f08

Please sign in to comment.