structlog v22.1.0 Release Notes
Release Date: 2022-07-20 // about 1 year ago-
โ Removed
- ๐ Python 3.6 is not supported anymore.
- Pickling is now only possible with protocol version 3 and newer.
๐ Deprecated
- ๐ The entire
structlog.threadlocal
module is deprecated. Please use the primitives fromstructlog.contextvars
instead.
If you're using the modern APIs (
bind_threadlocal()
/merge_threadlocal()
) it's enough to replace them 1:1 with theircontextvars
counterparts. 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.StackInfoRenderer
now 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 wayPrintLogger
used to work in previous versions. #403 #404 structlog.make_filtering_bound_logger()
-returned loggers now also have alog()
method to match thestructlog.stdlib.BoundLogger
signature closer. #413- โ Added structured logging of tracebacks via the
structlog.tracebacks
module, and most notably thestructlog.tracebacks.ExceptionDictTransformer
which can be used with the newstructlog.processors.ExceptionRenderer
to 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 configureslogging
to log to standard out at the passed log level. #428 structlog.processors.EventRenamer
allows you to rename the hitherto hard-coded event dict keyevent
to something else. Optionally, you can rename another key toevent
at the same time, too. So addingEventRenamer(to="msg", replace_by="_event")
to your processor pipeline will rename the standardevent
key tomsg
and then rename the_event
key toevent
. This allows you to use theevent
key 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_logs
now 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_contextvars
processor. That means you can usestructlog.contextvars
features without configuringstructlog
.
๐ Fixed
- ๐ Overloaded the
bind
,unbind
,try_unbind
andnew
methods in theFilteringBoundLogger
Protocol. This makes it easier to use objects of typeFilteringBoundLogger
in a typed context. #392 - 0๏ธโฃ Monkeypatched
sys.stdout
s 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
, andstackLevel
in the event dictionary. They are transformed into proper keyword arguments instead of putting them into theextra
dictionary. #424, #427
Previous changes from v21.5.0
-
Backward-incompatible changes:
none
๐ Deprecations: ^
none
๐ Changes: ^
- โ Added the
structlog.processors.LogfmtRenderer
processor to render log lines using thelogfmt <https://brandur.org/logfmt>
_ format.#376 <https://github.com/hynek/structlog/pull/376>
_ - โ Added the
structlog.stdlib.ExtraAdder
processor that adds extra attributes oflogging.LogRecord
objects to the event dictionary. This processor can be used for adding data passed in theextra
parameter of thelogging
module'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.CallsiteParameterAdder
processor 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