hynek / structlog

Simple, powerful, and fast logging for Python.
https://www.structlog.org/
Other
3.48k stars 220 forks source link

fixes bug in render_to_log_kwargs #620

Closed fraser-langton closed 4 months ago

fraser-langton commented 5 months ago

Summary

Fixes https://github.com/hynek/structlog/issues/619

render_to_log_kwargs reserves stackLevel when it should be stacklevel

python stdlib kwargs https://github.com/python/cpython/blob/main/Lib/logging/__init__.py#L1632

import structlog

structlog.configure(
    processors=[
        structlog.stdlib.render_to_log_kwargs,
    ],
    cache_logger_on_first_use=True,
)

log = structlog.get_logger()

log.info("test", stacklevel=2)  # doesn't error, but doesn't pass stacklevel to stdlib

log.info("test", stackLevel=2)  # errors as it passes stackLevel to stdlib
Traceback (most recent call last):
  File "C:\Users\user\Path\to\file.py", line 12, in <module>
    log.info("test", stacklevel=2)
  File "C:\Users\user\VirtualEnv\project\lib\site-packages\structlog\_log_levels.py", line 157, in meth
    return self._proxy_to_logger(name, event, **kw)
  File "C:\Users\user\VirtualEnv\project\lib\site-packages\structlog\_base.py", line 206, in _proxy_to_logger
    return getattr(self._logger, method_name)(*args, **kw)
TypeError: msg() got an unexpected keyword argument 'msg'

related https://github.com/hynek/structlog/issues/537 https://github.com/hynek/structlog/issues/424

Pull Request Check List

hynek commented 4 months ago

Thanks!