$ show hynek/structlog
structlog is a production-ready structured logging library for Python. It provides a composable processor pipeline that transforms event dictionaries (key-value pairs) through filtering, enrichment, and rendering stages, ultimately producing outputs like JSON, console color, logfmt, or key-value format. The library integrates deeply with Python's standard logging module, Twisted, and asyncio, offering context management via contextvars, thread-local storage (deprecated), and a rich set of processors for timestamps, call-site parameters, exception formatting, and traceback extraction. Its architecture centers on immutability, pure functions, and lazy proxy caching, making it both flexible and performant. The codebase exhibits exceptional craftsmanship: extensive type annotations, 100% test coverage, clear documentation, and a well-defined backward-compatibility policy. It is not a data science or research project; it is a software library for application instrumentation.
The LLM identified 1 files worth highlighting for reuse:
Converts Python exceptions into a tree of dataclasses (Trace, Stack, Frame, SyntaxError_) that are fully JSON-serializable. Handles exception groups, cause chains, recursion limits, and optional local variable representation. The core extraction logic is self-contained, using only the stdlib traceback module and a small internal helper for frame finding. This module could be extracted as a standalone library for generating structured, machine-readable traceback data from any Python exception, independent of structlog's logging context.