Skip to content

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.

Get started API reference

What it gives you

  • Drop-in for logging.basicConfig: stdlib-style format= strings via StdlibStyleFormatter
  • 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(...) — and Logger.set_level() that also propagates to stdlib
  • Named loggers with hierarchy and propagation
  • Structured extra fields and reusable context via Logger.bind()
  • Context-local fields via the Context namespace (Context.scope(...) doubles as a logfire span when configure_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 LogfireHandler and configure_logfire(...)
  • configure() and shutdown() 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