structlog v22.1.0 Release NotesRelease Date: 2022-07-20 // about 1 year ago
- 👍 Python 3.6 is not supported anymore.
- Pickling is now only possible with protocol version 3 and newer.
- 🗄 The entire
structlog.threadlocalmodule is deprecated. Please use the primitives from
If you're using the modern APIs (
merge_threadlocal()) it's enough to replace them 1:1 with their
contextvarscounterparts. The old approach around
wrap_dict()has been discouraged for a while.
Currently there are no concrete plans to remove the module, but no patches against it will be accepted from now on. #409
structlog.processors.StackInfoRenderernow has an additional_ignores parameter that allows you to filter out your own logging layer. #396
- ➕ Added
structlog.WriteLogger, a faster – but more low-level – alternative to
structlog.PrintLogger. It works the way
PrintLoggerused to work in previous versions. #403 #404
structlog.make_filtering_bound_logger()-returned loggers now also have a
log()method to match the
structlog.stdlib.BoundLoggersignature closer. #413
- ➕ Added structured logging of tracebacks via the
structlog.tracebacksmodule, and most notably the
structlog.tracebacks.ExceptionDictTransformerwhich can be used with the new
structlog.processors.ExceptionRendererto render JSON tracebacks. #407
structlog's defaults on top of standard library's
logging. It optionally also configures
loggingto log to standard out at the passed log level. #428
structlog.processors.EventRenamerallows you to rename the hitherto hard-coded event dict key
eventto something else. Optionally, you can rename another key to
eventat the same time, too. So adding
EventRenamer(to="msg", replace_by="_event")to your processor pipeline will rename the standard
msgand then rename the
event. This allows you to use the
eventkey in your own log files and to have consistent log message keys across languages.
structlog.dev.ConsoleRenderer(event_key="event")now allows to customize the name of the key that is used for the log message.
structlog.make_filtering_bound_logger()now returns a method with the same signature for all log levels, whether they are active or not. This ensures that invalid calls to inactive log levels are caught immediately and don't explode once the log level changes. #401
structlog.PrintLogger– that is used by default – now uses
print()for printing, making it a better citizen for interactive terminal applications. #399
structlog.testing.capture_logsnow works for already initialized bound loggers. #408
structlog.processors.format_exc_info()is no longer a function, but an instance of
structlog.processors.ExceptionRenderer. Its behavior has not changed. #407
- 🔧 The default configuration now includes the
structlog.contextvars.merge_contextvarsprocessor. That means you can use
structlog.contextvarsfeatures without configuring
- 📄 Overloaded the
newmethods in the
FilteringBoundLoggerProtocol. This makes it easier to use objects of type
FilteringBoundLoggerin a typed context. #392
- 0️⃣ Monkeypatched
sys.stdouts are now handled more gracefully by
ConsoleRenderer(that's used by default). #404
structlog.stdlib.render_to_log_kwargs()now correctly handles the presence of
stackLevelin the event dictionary. They are transformed into proper keyword arguments instead of putting them into the
extradictionary. #424, #427
Previous changes from v21.5.0
🗄 Deprecations: ^
🔄 Changes: ^
- ➕ Added the
structlog.processors.LogfmtRendererprocessor to render log lines using the
logfmt <https://brandur.org/logfmt>_ format.
- ➕ Added the
structlog.stdlib.ExtraAdderprocessor that adds extra attributes of
logging.LogRecordobjects to the event dictionary. This processor can be used for adding data passed in the
extraparameter of the
loggingmodule's log methods to the event dictionary.
- ➕ Added the
structlog.processor.CallsiteParameterAdderprocessor that adds parameters of the callsite that an event dictionary orginated from to the event dictionary. This processor can be used to enrich events dictionaries with information such as the function name, line number and filename that an event dictionary orignated from.
- ➕ Added the