Skip to main content

Zero-dependency structured logging library for the molcrafts ecosystem

Project description

mollog

CI PyPI Ruff Python Typed License Runtime

mollog is a typed, dependency-free structured logging library for Python applications that want clear output, small surface area, and explicit control.

Version 1.0.0 focuses on the pieces needed in real projects: hierarchical loggers, structured context, JSON/text formatting, queue-based fan-out, optional Rich console output, and predictable shutdown/configuration hooks.

Highlights

  • Zero required runtime dependencies
  • Typed public API with py.typed
  • configure() and shutdown() helpers for application setup
  • Structured extra, bind(), and context-local fields via bind_context() / scoped_context()
  • Text, JSON, file, rotating-file, timed-rotating, queue, and Rich handlers
  • Exception and stack capture built into the record model

Installation

Core package:

pip install molcrafts-mollog

Development environment:

pip install -e ".[dev,docs,rich]"

Rich terminal support:

pip install "molcrafts-mollog[rich]"

Quickstart

from mollog import JSONFormatter, StreamHandler, configure, get_logger

handler = StreamHandler()
handler.set_formatter(JSONFormatter())
configure(level="info", handlers=[handler])

logger = get_logger("api")
logger.info("request complete", status=200, duration_ms=18)

Contextual logging

from mollog import bind_context, get_logger, scoped_context

logger = get_logger("worker")

with scoped_context(request_id="req-42", trace_id="trace-7"):
    logger.bind(component="ingest").info("started")

token = bind_context(batch="nightly")
try:
    logger.info("continuing")
finally:
    from mollog import reset_context

    reset_context(token)

Exception logging

from mollog import get_logger

logger = get_logger("api")

try:
    raise ValueError("bad payload")
except ValueError:
    logger.exception("request failed", request_id="req-17")

Rich console output

from mollog import RichHandler, configure, get_logger

configure(handlers=[RichHandler()], level="debug")
logger = get_logger("cli")
logger.warning("unexpected value", field="charge", observed="2+")

Release-ready API surface

Core exports include:

  • get_logger()
  • configure()
  • shutdown()
  • bind_context()
  • scoped_context()
  • clear_context()
  • Logger, BoundLogger, LoggerManager
  • TextFormatter, JSONFormatter
  • StreamHandler, FileHandler, RotatingFileHandler, TimedRotatingFileHandler, QueueHandler
  • RichHandler with molcrafts-mollog[rich]

Documentation

The repository includes a Zensical documentation site.

uv run zensical serve

Build the static site:

uv run zensical build

Main pages:

Development

pip install ".[dev]"
pytest -q

See CONTRIBUTING.md for contribution workflow and RELEASING.md for the 1.x release process.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

molcrafts_mollog-1.0.0.tar.gz (26.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

molcrafts_mollog-1.0.0-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file molcrafts_mollog-1.0.0.tar.gz.

File metadata

  • Download URL: molcrafts_mollog-1.0.0.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for molcrafts_mollog-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f434bea996dd37e58123342a68c3f9ac9e5170f8f25c990bc4fa4b8f81f7008b
MD5 e2b50465818497a5e7e872330563024f
BLAKE2b-256 e57ff1d779d1bae794944bfd3926b841605595c6ae3e0c759557cacd72ecdb23

See more details on using hashes here.

Provenance

The following attestation bundles were made for molcrafts_mollog-1.0.0.tar.gz:

Publisher: release.yml on MolCrafts/mollog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file molcrafts_mollog-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for molcrafts_mollog-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4bf8d3aafef0bbf3df1b67f0fb8a243aa9ce51926f4fd4c080f86c03ab24973e
MD5 46d71211a93ed88acb90efdc8ebc7d36
BLAKE2b-256 a8b562304f457549c417df0a97017980ada61fedc22eeefd85166ef8efedfb3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for molcrafts_mollog-1.0.0-py3-none-any.whl:

Publisher: release.yml on MolCrafts/mollog

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page