README.md
June 1, 2026 · View on GitHub
mollog
Structured logging for Python with a stdlib-compatible API — no import logging required.
mollog is a structured logging library for Python that mirrors the standard library's logging API while adding structured extra fields, JSON output, context propagation, and a bridge that funnels stdlib records into its own hierarchy. Migrate from logging.basicConfig without changing your format strings.
Capabilities
| Module | Capability |
|---|---|
_manager | Singleton logger registry plus the top-level API: configure / basicConfig, get_logger / getLogger, set_level, shutdown, and trace/debug/info/warning/error/critical/exception helpers |
_logger | Named Logger with hierarchy, propagation, per-logger levels, bind() for reusable context, and exception/stack capture |
_record | Immutable frozen LogRecord dataclass — level, message, logger name, timestamp, extra, exception, stack info |
_level | Level enum — TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL — with coercion from ints, names, or enum values |
_context | Context namespace — thread- and asyncio-safe context fields via contextvars; Context.scope() doubles as a logfire span |
_handler | Handler base class plus StreamHandler and NullHandler |
_file_handler | FileHandler, RotatingFileHandler, and TimedRotatingFileHandler |
_queue | QueueHandler and background-thread QueueListener for thread/process-safe logging |
_formatter | Formatter base plus TextFormatter, JSONFormatter, and stdlib-style StdlibStyleFormatter |
_rich | RichFormatter — ANSI-styled, color-coded output via rich |
_filter | Filter base class and LevelFilter for level-range filtering |
_stdlib_bridge | StdlibBridgeHandler plus capture_stdlib_logging / release_stdlib_logging — routes stdlib logging records through mollog |
_logfire | Optional LogfireHandler and configure_logfire() for Pydantic Logfire backends |
Install
pip install molcrafts-mollog
# with the optional logfire backend
pip install "molcrafts-mollog[logfire]"
Requires Python 3.12+. The only runtime dependency is rich.
Quick start
import mollog
mollog.configure(
level="INFO",
format="%(asctime)s %(levelname)s %(name)s %(message)s",
)
mollog.get_logger("httpx").set_level("WARNING") # silence a noisy library
mollog.info("service booted", port=8080)
mollog.configure(...) accepts the same format= strings as logging.basicConfig, and by default installs a bridge so records emitted by libraries that still use stdlib logging (httpx, urllib3, openai, …) flow through mollog's hierarchy. Disable with capture_stdlib=False.
Documentation
The full guide lives in docs/:
MolCrafts ecosystem
| Project | Role |
|---|---|
| molpy | Python toolkit — the shared molecular data model & workflow layer |
| molrs | Rust core — molecular data structures & compute kernels (native + WASM) |
| molpack | Packmol-grade molecular packing (Rust + Python) |
| molvis | WebGL molecular visualization & editing |
| molexp | Workflow & experiment-management platform |
| molnex | Molecular machine-learning framework |
| molq | Unified job queue — local / SLURM / PBS / LSF |
| molcfg | Layered configuration library |
| mollog | Structured logging, stdlib-compatible — this repo |
| molhub | Molecular dataset hub |
| molmcp | MCP server for the ecosystem |
| molrec | Atomistic record specification |
Contributing
See CONTRIBUTING.md.
License
BSD-3-Clause — see LICENSE.