Structured Logging for Python
Project description
structlog is the production-ready logging solution for Python:
- Simple: Everything is about functions that take and return dictionaries – all hidden behind familiar APIs.
- Powerful: Functions and dictionaries aren’t just simple but also powerful. structlog leaves you in control.
- Fast: structlog is not hamstrung by designs of yore. Its flexibility comes not at the price of performance.
Thanks to its flexible design, you choose whether you want structlog to take care of the output of your log entries or whether you prefer to forward them to an existing logging system like the standard library's logging module.
The output format is just as flexible and structlog comes with support for JSON, logfmt, as well as pretty console output out-of-the-box:
Sponsors
structlog would not be possible without our amazing sponsors. Especially those generously supporting us at the The Organization tier and higher:
Please consider joining them to help make structlog’s maintenance more sustainable!
Introduction
structlog has been successfully used in production at every scale since 2013, while embracing cutting-edge technologies like asyncio, context variables, or type hints as they emerged. Its paradigms proved influential enough to help design structured logging packages across ecosystems.
Project Links
- Get Help (use the structlog tag on Stack Overflow)
- PyPI
- GitHub
- Documentation
- Changelog
- Third-party Extensions
structlog for Enterprise
Available as part of the Tidelift Subscription.
The maintainers of structlog and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use.
Release Information
Deprecated
structlog.dev.ConsoleRenderer()'s pad_event argument has been renamed to pad_event_to to differentiate it from the boolean pad_level argument. pad_event is now deprecated.
Added
-
Added
structlog.dev.ConsoleRenderer.get_active()that returns the currently activestructlog.dev.ConsoleRenderer(). #749 -
structlog.dev.ConsoleRenderer()now supports setting theexception_formatterattribute.You can now disable the pretty-printing of exceptions by setting it to
structlog.dev.plain_traceback:cr = structlog.dev.ConsoleRenderer.get_active() cr.exception_formatter = structlog.dev.plain_traceback
Same goes for sort_keys, columns, colors, force_colors, level_styles, pad_event_to, event_key, timestamp_key, and repr_native_str.
-
Added
structlog.dev.ConsoleRenderer.get_default_column_styles()for reuse the default column styles. #741 -
structlog.testing.capture_logs()now optionally accepts processors to apply before capture. #728 -
structlog.dev.RichTracebackFormatternow exposes the upstream code_width parameter. Default width is nowNonefor full terminal width. Full terminal width is now handled by Rich itself, bringing support for reflow andCOLUMNenvironment variable. Passing-1for width is now deprecated and automatically replaced byNone. #717 -
Native loggers now allow the passing of a dictionary for dictionary-based interpolation
log.info("hello %(name)s!", {"name": "world"}). #748 -
On Python 3.11+,
structlog.processors.CallsiteParameterAddernow supportsCallsiteParameter.QUAL_NAMEthat adds the qualified name of the callsite, including scope and class names. This is only available for structlog-originated events since the standard library has no equivalent. -
structlog.stdlib.LoggerFactorynow supports the stacklevel parameter. #763
Changed
structlog.dev.rich_traceback()now throws a more helpful error when Rich is missing. #735
Fixed
-
structlog.processors.MaybeTimeStampernow respects the key argument when determining whether to overwrite the timestamp field. #747 -
structlog.tracebacks.extract()no longer raises aRecursionErrorwhen the cause chain of an exception contains itself. #739 -
Default config now respects
FORCE_COLORon Windows. #758
Credits
structlog is written and maintained by Hynek Schlawack. The idea of bound loggers is inspired by previous work by Jean-Paul Calderone and David Reid.
The development is kindly supported by my employer Variomedia AG, structlog’s Tidelift subscribers, and all my amazing GitHub Sponsors.
The logs-loving beaver logo has been contributed by Lynn Root.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file structlog-25.5.0.tar.gz.
File metadata
- Download URL: structlog-25.5.0.tar.gz
- Upload date:
- Size: 1.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
098522a3bebed9153d4570c6d0288abf80a031dfdb2048d59a49e9dc2190fc98
|
|
| MD5 |
a36a8ab827f29761fe262ae5ad5cb72f
|
|
| BLAKE2b-256 |
ef529ba0f43b686e7f3ddfeaa78ac3af750292662284b3661e91ad5494f21dbc
|
Provenance
The following attestation bundles were made for structlog-25.5.0.tar.gz:
Publisher:
pypi-package.yml on hynek/structlog
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
structlog-25.5.0.tar.gz -
Subject digest:
098522a3bebed9153d4570c6d0288abf80a031dfdb2048d59a49e9dc2190fc98 - Sigstore transparency entry: 644110934
- Sigstore integration time:
-
Permalink:
hynek/structlog@c0ef9e09e7a536cae65e33c1ac1c8b4e6a6f7511 -
Branch / Tag:
refs/tags/25.5.0 - Owner: https://github.com/hynek
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-package.yml@c0ef9e09e7a536cae65e33c1ac1c8b4e6a6f7511 -
Trigger Event:
release
-
Statement type:
File details
Details for the file structlog-25.5.0-py3-none-any.whl.
File metadata
- Download URL: structlog-25.5.0-py3-none-any.whl
- Upload date:
- Size: 72.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8453e9b9e636ec59bd9e79bbd4a72f025981b3ba0f5837aebf48f02f37a7f9f
|
|
| MD5 |
f4f0e8f5a778b9aa05c8f6faa154aa65
|
|
| BLAKE2b-256 |
a845a132b9074aa18e799b891b91ad72133c98d8042c70f6240e4c5f9dabee2f
|
Provenance
The following attestation bundles were made for structlog-25.5.0-py3-none-any.whl:
Publisher:
pypi-package.yml on hynek/structlog
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
structlog-25.5.0-py3-none-any.whl -
Subject digest:
a8453e9b9e636ec59bd9e79bbd4a72f025981b3ba0f5837aebf48f02f37a7f9f - Sigstore transparency entry: 644110973
- Sigstore integration time:
-
Permalink:
hynek/structlog@c0ef9e09e7a536cae65e33c1ac1c8b4e6a6f7511 -
Branch / Tag:
refs/tags/25.5.0 - Owner: https://github.com/hynek
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-package.yml@c0ef9e09e7a536cae65e33c1ac1c8b4e6a6f7511 -
Trigger Event:
release
-
Statement type: