microsoft/picologging

log `extra` param does not work with picologging

Opened this issue · 1 comments

Passing the extra param on log calls behaves different in picologging compared to stdlib.

Sample code:

import logging
# import picologging as logging

logging.basicConfig(format="message=%(message)s foo=%(foo)s", level=logging.DEBUG)
logging.debug("msg", extra={"foo": "bar"})

Output with std logging: message=msg foo=bar
Output with picologging: AttributeError: 'picologging.LogRecord' object has no attribute 'foo'

stdlib logging will update LogRecord.__dict__ directly to add the extra items to the log record object.
https://github.com/python/cpython/blob/main/Lib/logging/__init__.py#L1620-L1624

But, just in case you plan to change this behaviour :)... For my personal use case (JSON structured logging), it would be best if extra was simply a field in LogRecord that I could access in a custom Formatter.