-
-
Notifications
You must be signed in to change notification settings - Fork 251
Closed
Description
structlog.processors.add_log_level used to report the level of "exception" events as "error", but since 23.3.0 with certain configurations it's possible to get "exception" instead:
$ pip3 install structlog==23.2.0 && python3 main.py
{'exc_info': True, 'event': 'test', '_record': <LogRecord: root, 40, 223, "{...}">, '_from_structlog': True, 'level': 'error'}
$ pip3 install structlog==23.3.0 && python3 main.py
{'exc_info': True, 'event': 'test', '_record': <LogRecord: root, 40, 217, "{...}">, '_from_structlog': True, 'level': 'exception'}
I wonder if this is intentional, since it's not very clearly listed in the changelog. There is "stdlib: structlog.stdlib.BoundLogger.exception()'s handling ofLogRecord.exc_info is now set consistent with logging." but I don't think this change falls into that category.
It seems to be reliant on wrapper_class=structlog.stdlib.BoundLogger
.
Example code:
import logging.config
import structlog
structlog.configure(
processors=[
structlog.stdlib.ProcessorFormatter.wrap_for_formatter,
],
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
)
logging_config = {
"version": 1,
"formatters": {
"json": {
"()": structlog.stdlib.ProcessorFormatter,
"processors": [
structlog.processors.add_log_level,
],
}
},
"handlers": {
"json": {
"class": "logging.StreamHandler",
"formatter": "json",
},
},
"root": {
"handlers": ["json"],
},
}
logging.config.dictConfig(logging_config)
Metadata
Metadata
Assignees
Labels
No labels