README.md

June 1, 2026 · View on GitHub

 mollog

Structured logging for Python with a stdlib-compatible API — no import logging required.

CI PyPI Python License Ruff

Documentation  ·  Quick start  ·  Ecosystem

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

ModuleCapability
_managerSingleton logger registry plus the top-level API: configure / basicConfig, get_logger / getLogger, set_level, shutdown, and trace/debug/info/warning/error/critical/exception helpers
_loggerNamed Logger with hierarchy, propagation, per-logger levels, bind() for reusable context, and exception/stack capture
_recordImmutable frozen LogRecord dataclass — level, message, logger name, timestamp, extra, exception, stack info
_levelLevel enum — TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL — with coercion from ints, names, or enum values
_contextContext namespace — thread- and asyncio-safe context fields via contextvars; Context.scope() doubles as a logfire span
_handlerHandler base class plus StreamHandler and NullHandler
_file_handlerFileHandler, RotatingFileHandler, and TimedRotatingFileHandler
_queueQueueHandler and background-thread QueueListener for thread/process-safe logging
_formatterFormatter base plus TextFormatter, JSONFormatter, and stdlib-style StdlibStyleFormatter
_richRichFormatter — ANSI-styled, color-coded output via rich
_filterFilter base class and LevelFilter for level-range filtering
_stdlib_bridgeStdlibBridgeHandler plus capture_stdlib_logging / release_stdlib_logging — routes stdlib logging records through mollog
_logfireOptional 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

ProjectRole
molpyPython toolkit — the shared molecular data model & workflow layer
molrsRust core — molecular data structures & compute kernels (native + WASM)
molpackPackmol-grade molecular packing (Rust + Python)
molvisWebGL molecular visualization & editing
molexpWorkflow & experiment-management platform
molnexMolecular machine-learning framework
molqUnified job queue — local / SLURM / PBS / LSF
molcfgLayered configuration library
mollogStructured logging, stdlib-compatible — this repo
molhubMolecular dataset hub
molmcpMCP server for the ecosystem
molrecAtomistic record specification

Contributing

See CONTRIBUTING.md.

License

BSD-3-Clause — see LICENSE.


Crafted with 💚 by MolCrafts