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: Development and prerelease code 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.

⌨️ 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.0.tar.gz (16.4 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.0-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: liblaf_logging-0.1.0.tar.gz
  • Upload date:
  • Size: 16.4 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.0.tar.gz
Algorithm Hash digest
SHA256 939e92a49a342cc40d5c7bf080c16c0a88722814d5db11b8a10a5f8d8d761c4f
MD5 67767343d29769956131a45a07b6351d
BLAKE2b-256 9eb20d06de1d1842f5a9251bfc45dbcc42da9d12f355656b93181ca353679e55

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: liblaf_logging-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b8ba76fa69ddd6fea68be6f80a1a178408d20dc5d8bf7975d1242520cc9f9dc
MD5 30b2ab1c315501fd87b5d75bbf6401c7
BLAKE2b-256 53aa389974b6438c2e4946665491ff4ce83bff6ab1a61b46a0c315da7352d7b5

See more details on using hashes here.

Provenance

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