mollog
Structured logging for Python with a stdlib-compatible API — projects can drop import logging entirely while keeping access to %(asctime)s-style format strings and the third-party library ecosystem that emits through stdlib.
What it gives you
- Drop-in for
logging.basicConfig: stdlib-styleformat=strings viaStdlibStyleFormatter - Stdlib bridge that captures records from libraries which still use
logging(httpx, urllib3, openai, …) and routes them through mollog - Top-level helpers —
mollog.info(...),mollog.warning(...),mollog.set_level(...)— andLogger.set_level()that also propagates to stdlib - Named loggers with hierarchy and propagation
- Structured
extrafields and reusable context viaLogger.bind() - Context-local fields via the
Contextnamespace (Context.scope(...)doubles as a logfire span whenconfigure_logfire(...)has been called) - Exception and stack capture on every record
- Text, JSON, Rich, and stdlib-style formatters
- Stream, file, rotating-file, timed-rotating, queue, and null handlers
- Optional Logfire backend via
LogfireHandlerandconfigure_logfire(...) configure()andshutdown()helpers for application lifecycle
Quick example
```python import mollog
mollog.configure( level="INFO", format="%(asctime)s %(levelname)s %(name)s %(message)s", ) mollog.get_logger("httpx").set_level("WARNING")
mollog.info("service booted", port=8080) ```
Documentation map
- Getting Started — installation, setup, common patterns
- Configuration — root logger setup, stdlib bridge, teardown
- Context Propagation — request and task scoped metadata
- Behavior — concurrency, reserved fields, shutdown semantics
- Logfire — optional Pydantic Logfire backend
- Rich Console — colored terminal output
- API Reference — complete exported surface