This is a (too) big release, so it has many highlights!
Firstly, rendering exceptions in machine-readable logs (usually JSON) got a big upgrade: thanks to structlog.processors.dict_tracebacks you can now have fully structured exceptions in your logs!
To ease getting started with structlog, we're now shipping structlog.stdlib.recreate_defaults() that recreates structlog's default behavior, but on top of standard library's logging. The output looks the same, but it runs through logging's machinery and integrates itself easier. The default configuration now also merges your contextvars-based context, so enjoy structlog.contextvars.bind_contextvars() without configuring anything!
Another request wish that kept coming up is naming the message key differently than event. We're aware that nowadays keys like msg are more common, but structlog pre-dates the software that introduced and popularized it. To allow for more consistency across your platforms, structlog now ships structlog.processors.EventRenamer that allows you to rename the default event key to something else and additionally also allows you to rename another key to event.
None of my projects would exist in their current form without you!
Full Changelog
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 from structlog.contextvars instead.
If you're using the modern APIs (bind_threadlocal() / merge_threadlocal()) it's enough to replace them 1:1 with their contextvars counterparts. 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
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 to structlog.PrintLogger. It works the way PrintLogger used 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.BoundLogger signature closer. #413
Added structured logging of tracebacks via the structlog.tracebacks module, and most notably the structlog.tracebacks.ExceptionDictTransformer which can be used with the new structlog.processors.ExceptionRenderer to render JSON tracebacks. #407
structlog.stdlib.recreate_defaults(log_level=logging.NOTSET) that recreates structlog's defaults on top of standard library's logging. It optionally also configures logging to log to standard out at the passed log level. #428
structlog.processors.EventRenamer allows you to rename the hitherto hard-coded event dict key event to something else. Optionally, you can rename another key to event at the same time, too. So adding EventRenamer(to="msg", replace_by="_event") to your processor pipeline will rename the standard event key to msg and then rename the _event key to event. This allows you to use the event 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
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_logs now 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_contextvars processor. That means you can use structlog.contextvars features without configuring structlog.
Pickling is now only possible with protocol version 3 and newer.
Deprecated
The entire structlog.threadlocal module is deprecated.
Please use the primitives from structlog.contextvars instead.
If you're using the modern APIs (bind_threadlocal() / merge_threadlocal()) it's enough to replace them 1:1 with their contextvars counterparts.
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
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 to structlog.PrintLogger.
It works the way PrintLogger used 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.BoundLogger signature closer.
#413
Added structured logging of tracebacks via the structlog.tracebacks module,
and most notably the structlog.tracebacks.ExceptionDictTransformer which can be used with the new structlog.processors.ExceptionRenderer to render JSON tracebacks.
#407
structlog.stdlib.recreate_defaults(log_level=logging.NOTSET) that recreates structlog's defaults on top of standard library's logging.
It optionally also configures logging to log to standard out at the passed log level.
#428
structlog.processors.EventRenamer allows you to rename the hitherto hard-coded event dict key event to something else.
Optionally, you can rename another key to event at the same time, too.
So adding EventRenamer(to="msg", replace_by="_event") to your processor pipeline will rename the standard event key to msg and then rename the _event key to event.
This allows you to use the event 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
structlog.PrintLogger – that is used by default – now uses print() for printing, making it a better citizen for interactive terminal applications.
#399
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Bumps structlog from 21.5.0 to 22.1.0.
Release notes
Sourced from structlog's releases.
... (truncated)
Changelog
Sourced from structlog's changelog.
... (truncated)
Commits
0ca06b7
Prepare 22.1.0425b7e1
Ignore compare links (they may not exist yet)646e9fc
Add NOTICE to sdist6b30f49
Fix broken links63e1dcd
Steal Rust's dual-license handling again9b2458b
Clarify licensing/contribution of trackbacks.py6fb6e7a
Add annotations future import to src/* for consistency414475d
Add structlog.contextvars.merge_contextvars to default configd366240
Fix grammar & clarity70deda6
Clarify license in docs, cleanup indexDependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting
@dependabot rebase
.Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)