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: Module-level helpers resolve the first visible caller so log records keep useful logger names, functions, and line numbers.
  • Rich output everywhere: Console and file handlers share Rich rendering, compact columns, highlighted messages, and Rich tracebacks.
  • Per-record rate limits: Add extra={"limits": "1/minute"} or LimitOptions to suppress noisy repeated records.
  • Process hooks: init() captures warnings and installs hooks for uncaught and unraisable exceptions.
  • Release-aware defaults: .devN and prerelease distributions can log more verbosely while stable installed packages stay quiet.

📦 Installation

uv add liblaf-logging

🚀 Quick Start

import liblaf.logging

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

init() configures process-wide logging. When it manages handlers itself, it creates a Rich console handler, optionally creates a Rich-formatted file handler, and attaches LimitsFilter to those managed handlers.

Use the module-level helpers when shared helpers should log as their caller.

import liblaf.logging


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

🚦 Rate-Limited Records

import liblaf.logging

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

For shared buckets or custom 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

Runtime settings are backed by liblaf-conf and the LOG_ environment prefix.

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

Settings control the default level, optional file path, timestamp format, relative timestamp display, hidden-frame prefixes, and release-aware traceback or warning filtering.

🧭 Release-Aware Defaults

SanitizedLogger raises the default level for modules that belong to selected installed distributions. .devN distributions use the development level, prerelease distributions use the prerelease level, and stable distributions keep the standard NOTSET logger default.

Only metadata from selected .devN or prerelease distributions is expanded. Exact files are matched directly, and .pth files in those distributions add source-tree prefixes. direct_url.json is intentionally not followed, so stable editable installs stay stable unless their distribution version is marked as development or prerelease.

⌨️ 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.1.tar.gz (16.5 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.1-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: liblaf_logging-0.1.1.tar.gz
  • Upload date:
  • Size: 16.5 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.1.tar.gz
Algorithm Hash digest
SHA256 58f46bed71de135bb2893cf8e5c0e66b98058387f61a756e5d385c57911b259b
MD5 c02e2bea987ee1a0e168bf3223c776a9
BLAKE2b-256 e670aadf6226733e73f9d35ef711b5687599f1a9b10abc0b260be8dbe5bfde51

See more details on using hashes here.

Provenance

The following attestation bundles were made for liblaf_logging-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: liblaf_logging-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 24.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b066c9b876a1c059f60ec85eb6b3c850ae1b7ab2e470962e215c5ede5dca14f0
MD5 d82501afcc756765747e836fb9e56ea6
BLAKE2b-256 5d472037a9af21f26fcdf576f2d846a0dd17f81b9c4ab456eac55bf45a094db7

See more details on using hashes here.

Provenance

The following attestation bundles were made for liblaf_logging-0.1.1-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