Change8

25.5.0

📦 structlogView on GitHub →
9 features🐛 4 fixes2 deprecations🔧 11 symbols

Summary

This release adds mutable ConsoleRenderer with get_active, new configuration options, several new utilities, and fixes bugs around timestamp handling, traceback extraction, and color support.

Migration Steps

  1. Replace any usage of the pad_event argument in ConsoleRenderer with pad_event_to.
  2. If you passed -1 for width to RichTracebackFormatter, change it to None (or omit the argument) to get full terminal width.
  3. Update code that relied on the previous immutable ConsoleRenderer configuration to use the new mutable attributes via get_active().

✨ New Features

  • Added structlog.dev.ConsoleRenderer.get_active() to retrieve the currently active ConsoleRenderer instance.
  • ConsoleRenderer now allows mutable configuration, including setting exception_formatter attribute.
  • Added structlog.dev.ConsoleRenderer.get_default_column_styles() for reusing default column styles.
  • structlog.testing.capture_logs() now accepts an optional processors argument to apply processors before capture.
  • RichTracebackFormatter now exposes the upstream code_width parameter and defaults width to None for full terminal width.
  • Native loggers accept a dictionary for %-style interpolation, e.g., log.info(\"hello %(name)s!\", {\"name\": \"world\"}).
  • CallsiteParameterAdder now supports CallsiteParameter.QUAL_NAME on Python 3.11+, adding qualified callsite names.
  • LoggerFactory now supports a stacklevel parameter.
  • rich_traceback() now raises a clearer error when Rich library is missing.

🐛 Bug Fixes

  • MaybeTimeStamper now respects the key argument when deciding whether to overwrite the timestamp field.
  • tracebacks.extract() no longer raises RecursionError when an exception's cause chain contains itself.
  • Default configuration now respects FORCE_COLOR environment variable on Windows.
  • rich_traceback() now throws a more helpful error if Rich is not installed.

Affected Symbols

⚡ Deprecations

  • pad_event argument of structlog.dev.ConsoleRenderer() renamed to pad_event_to and is now deprecated; update code to use pad_event_to.
  • Passing -1 for the width parameter of structlog.dev.RichTracebackFormatter is deprecated and will be automatically replaced by None.