structlog v22.1.0 Release Notes
Release Date: 2022-07-20 // over 3 years ago-
โ Removed
- ๐ Python 3.6 is not supported anymore.
- Pickling is now only possible with protocol version 3 and newer.
๐ Deprecated
- ๐ The entire
structlog.threadlocalmodule is deprecated. Please use the primitives fromstructlog.contextvarsinstead.
If you're using the modern APIs (
bind_threadlocal()/merge_threadlocal()) it's enough to replace them 1:1 with theircontextvarscounterparts. The old approach aroundwrap_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
โ Added
- โ
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 tostructlog.PrintLogger. It works the wayPrintLoggerused to work in previous versions. #403 #404 structlog.make_filtering_bound_logger()-returned loggers now also have alog()method to match thestructlog.stdlib.BoundLoggersignature closer. #413- โ Added structured logging of tracebacks via the
structlog.tracebacksmodule, and most notably thestructlog.tracebacks.ExceptionDictTransformerwhich can be used with the newstructlog.processors.ExceptionRendererto render JSON tracebacks. #407 - 0๏ธโฃ
structlog.stdlib.recreate_defaults(log_level=logging.NOTSET)that recreatesstructlog's defaults on top of standard library'slogging. It optionally also configuresloggingto log to standard out at the passed log level. #428 structlog.processors.EventRenamerallows you to rename the hitherto hard-coded event dict keyeventto something else. Optionally, you can rename another key toeventat the same time, too. So addingEventRenamer(to="msg", replace_by="_event")to your processor pipeline will rename the standardeventkey tomsgand then rename the_eventkey toevent. This allows you to use theeventkey 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.
๐ Changed
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- 0๏ธโฃ
structlog.PrintLoggerโ that is used by default โ now usesprint()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 ofstructlog.processors.ExceptionRenderer. Its behavior has not changed. #407- ๐ง The default configuration now includes the
structlog.contextvars.merge_contextvarsprocessor. That means you can usestructlog.contextvarsfeatures without configuringstructlog.
๐ Fixed
- ๐ Overloaded the
bind,unbind,try_unbindandnewmethods in theFilteringBoundLoggerProtocol. This makes it easier to use objects of typeFilteringBoundLoggerin a typed context. #392 - 0๏ธโฃ Monkeypatched
sys.stdouts are now handled more gracefully byConsoleRenderer(that's used by default). #404 structlog.stdlib.render_to_log_kwargs()now correctly handles the presence ofexc_info,stack_info, andstackLevelin the event dictionary. They are transformed into proper keyword arguments instead of putting them into theextradictionary. #424, #427
Previous changes from v21.5.0
-
Backward-incompatible changes:
none
๐ Deprecations: ^
none
๐ Changes: ^
- โ Added the
structlog.processors.LogfmtRendererprocessor to render log lines using thelogfmt <https://brandur.org/logfmt>_ format.#376 <https://github.com/hynek/structlog/pull/376>_ - โ Added the
structlog.stdlib.ExtraAdderprocessor that adds extra attributes oflogging.LogRecordobjects to the event dictionary. This processor can be used for adding data passed in theextraparameter of theloggingmodule's log methods to the event dictionary.#209 <https://github.com/hynek/structlog/pull/209>_#377 <https://github.com/hynek/structlog/pull/377>_ - โ 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.#380 <https://github.com/hynek/structlog/pull/380>_
- โ Added the