picologging icon indicating copy to clipboard operation
picologging copied to clipboard

log `extra` param does not work with picologging

Open GabrielCappelli opened this issue 2 years ago • 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'

GabrielCappelli avatar Nov 04 '23 17:11 GabrielCappelli

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.

GabrielCappelli avatar Nov 04 '23 17:11 GabrielCappelli