You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This wrapper is not very pretty due to issues that, I think, are related to the current implementation and definition of ProcessorFormatter:
structlog.stdlib.ProcessorFormatter inherit logging.Formatter but does not respect the positional arguments of its parent class for the init method. This makes a wrapper necessary since logging configuration from file tries to initialize formatter with positional arguments.
structlog.stdlib.ProcessorFormatter use positional arguments with default values and not keyword-only arguments. As a consequence, to forward standard logging.Formatter*args, one must copy all structlog.stdlib.ProcessorFormatter default values.
I think either StructlogFormatter should be changed, since it does not respect the signature of the parent class or an alternative class should be provided to make this kind of wrapper less cumbersome and more resilient to structlog internal code changes.
The text was updated successfully, but these errors were encountered:
Hi,
I wanted to use
StructlogFormatter
withinlogging
, with logging configuration loaded at runtime with a json file config.I ended up doing a small wrapper to make
structlog.stdlib.ProcessorFormatter
compatible with standardlogging.Formatter
:This wrapper is not very pretty due to issues that, I think, are related to the current implementation and definition of
ProcessorFormatter
:structlog.stdlib.ProcessorFormatter
inheritlogging.Formatter
but does not respect the positional arguments of its parent class for the init method. This makes a wrapper necessary since logging configuration from file tries to initialize formatter with positional arguments.structlog.stdlib.ProcessorFormatter
use positional arguments with default values and not keyword-only arguments. As a consequence, to forward standardlogging.Formatter
*args
, one must copy allstructlog.stdlib.ProcessorFormatter
default values.ProcessorFormatter
calls the init method oflogging.Formatter
withsuper().__init__(*args, fmt=fmt, **kwargs)
, and sincefmt
is the first positional argument oflogging.Formatter
, trying to forward any*args
will crash asfmt
will be provided twice (once as a positional arg and once as a keyword).I think either
StructlogFormatter
should be changed, since it does not respect the signature of the parent class or an alternative class should be provided to make this kind of wrapper less cumbersome and more resilient to structlog internal code changes.The text was updated successfully, but these errors were encountered: