Skip to main content

Caller-aware Rich logging for Python with rate limits, file output, warning hooks, and release-aware defaults.

Project description

✨ Features

  • Caller-aware helpers: liblaf.logging.info() and friends attribute shared helper logs to the first visible caller frame.
  • Rich console and file output: Handlers render compact time, level, location, highlighted messages, Rich renderables, pretty objects, and tracebacks.
  • Scoped array and tensor summaries: NumPy, Torch, and JAX output is compacted while records are rendered when those libraries are already imported.
  • Per-record rate limits: Add extra={"limits": "1/minute"} or a LimitOptions object to suppress noisy repeat logs.
  • Process hooks: init() captures warnings, uncaught exceptions, and unraisable exceptions through the standard logging pipeline.
  • Release-aware defaults: Development and prerelease distributions can get louder logger defaults while stable installed modules stay at NOTSET.

📦 Installation

uv add liblaf-logging

🚀 Quick Start

import liblaf.logging

liblaf.logging.init(force=True)
liblaf.logging.info("ready")

init() configures the root logger at INFO by default, installs Rich output, registers TRACE and ICECREAM level names, captures warnings, and adds exception hooks. When it creates handlers itself, each managed handler receives a LimitsFilter. While a record is rendered, NumPy, Torch, and JAX print options are scoped to compact summaries if those libraries are already loaded.

Use the module-level helpers when library or framework glue should log as the application code that called it.

import liblaf.logging


def announce() -> None:
    liblaf.logging.info("starting")

🚦 Rate Limits

Attach a limits value to an individual record.

import liblaf.logging

liblaf.logging.warning("still waiting", extra={"limits": "1/minute"})

For shared buckets, custom identifiers, or non-default costs, pass LimitOptions.

from liblaf.logging.filters import LimitOptions

liblaf.logging.warning(
    "sync retry",
    extra={
        "limits": LimitOptions(
            "5/minute",
            namespace=("sync",),
            identifiers=("account-42",),
            cost=1,
        )
    },
)

⚙️ Configuration

Settings use the LOG_ environment prefix through liblaf-conf. The most common options are LOG_LEVEL, LOG_FILE, LOG_TIME_RELATIVE, LOG_HIDE_FRAME, and LOG_HIDE_STABLE_RELEASE.

LOG_LEVEL=DEBUG LOG_FILE=logs/app.log python app.py

🧭 Release-Aware Defaults

SanitizedLogger checks module files against selected installed distributions when a logger is created without an explicit level. .devN distributions use the development level, prerelease distributions use the prerelease level, and stable distributions keep the normal NOTSET logger default.

The classifier expands metadata only for those selected distributions. Exact files are matched directly, and .pth files from selected distributions add source-tree prefixes for editable-style layouts. Stable distribution metadata is not expanded, and direct_url.json is not followed.

⌨️ Local Development

git clone https://github.com/liblaf/logging.git
cd logging
uv sync
uv run pytest
mise run docs:build

📝 License

Copyright © 2026 liblaf.
This project is MIT licensed.

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

liblaf_logging-0.1.4.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

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

liblaf_logging-0.1.4-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file liblaf_logging-0.1.4.tar.gz.

File metadata

  • Download URL: liblaf_logging-0.1.4.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for liblaf_logging-0.1.4.tar.gz
Algorithm Hash digest
SHA256 25e9ec08cf8f3034efae9200495852e96f38dd5e43496f7c51c667d11fd63a88
MD5 8be87a54a0d5a285b4b9b7619484d42a
BLAKE2b-256 6f552c0cf9c7e40c72f353ac15b449ae048790e0ae4b80115b74ad96d2a06b98

See more details on using hashes here.

Provenance

The following attestation bundles were made for liblaf_logging-0.1.4.tar.gz:

Publisher: python-release.yaml on liblaf/logging

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

File details

Details for the file liblaf_logging-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: liblaf_logging-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 28.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for liblaf_logging-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b363df8fbd8e6a1e44c444fb1687824e1598af2c0bc082e7948ecbd6b8888fd0
MD5 380ca5ad9c83956902453e1eab03a4a5
BLAKE2b-256 8b4311f7d04f21ee7b01130be4cc7b64cac727bcadd4bc408cd56d6a0a7440c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for liblaf_logging-0.1.4-py3-none-any.whl:

Publisher: python-release.yaml on liblaf/logging

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