Skip to main content

lfp-logging

A simple, zero-dependency logging utility for Python that provides lazy-initialization and automatic configuration.

Features

  • Lazy Initialization: Logging is only configured when the first log message is actually handled. It uses a patching mechanism that stays out of the way until a log is emitted.
  • Automatic Name Discovery: Automatically determines logger names based on the caller's class, module, or file name.
  • Smart Default Handlers:
    • INFO messages are sent to stderr (along with all other levels) by default.
    • Detailed formatting including timestamps, levels, and line numbers.
  • ANSI Colors: Automatic color support for terminals, with overrides for popular IDEs (VSCode, PyCharm) and CI environments.
  • Explicit Override Support: If you call logging.basicConfig() yourself, lfp-logging will automatically back off and let your configuration take priority.
  • Flexible Configuration: Supports configuration via environment variables.
  • Multi-platform Support: Supports macOS (ARM/x64), Linux (ARM/x64), and Windows (x64/ARM).

Installation

You can install lfp-logging directly from GitHub using pip:

pip install git+https://github.com/regbo/lfp-logging-py.git

Or add it to your pyproject.toml dependencies:

dependencies = [
    "lfp_logging @ git+https://github.com/regbo/lfp-logging-py.git"
]

Quick Start

from lfp_logging import logger

# The logger name is automatically discovered as the class name "MyService"
class MyService:
    def __init__(self):
        self.log = logger()
    
    def do_something(self):
        self.log.info("Starting task...")
        self.log.warning("Something might be wrong.")

# You can specify one or more potential names. 
# The first valid name (non-empty, not "__main__") will be used.
log = logger(None, "__main__", "my_app")
log.info("Hello World!") # Uses "my_app"

Configuration

The logging level and formats can be controlled using environment variables.

Environment Variables

  • LOG_LEVEL: Set the global log level. Accepts names (e.g., DEBUG, INFO) or numeric values (e.g., 10, 20).
  • LOG_FORMAT: Custom log format string (standard Python logging format). (Default: %(asctime)s %(levelname)s %(name)s:%(lineno)d %(message)s)
  • LOG_FORMAT_DATE: Custom date format (default: %Y-%m-%d %H:%M:%S).
  • LOG_FORMAT_COLOR: Global ANSI color code for all levels (e.g., \x1b[32m for green).
  • LOG_FORMAT_COLOR_<LEVEL>: Level-specific ANSI color code (e.g., LOG_FORMAT_COLOR_DEBUG).
  • LOG_CONFIG_LAZY: Defer logging configuration until the first log message is emitted (default: false). Set to true, 1, yes, or on to enable. When set to false, logging is configured immediately when logger() is called.

Automatic Back-off

lfp-logging is designed to be non-intrusive:

  • Pre-existing Config: If you call logging.basicConfig() or otherwise configure the root logger before any lfp-logging activity, it will detect this and skip its own configuration.
  • Post-initialization Override: If you call logging.basicConfig() after lfp-logging has already configured itself, lfp-logging will automatically remove its default handler to allow your new configuration to take full effect.

System Arguments

The --log-level argument is no longer supported directly by the core configuration, but can be implemented by the user by setting the LOG_LEVEL environment variable before the first log call.

Development

This project uses uv for dependency management and pytest for testing.

Running Tests

uv run pytest

Metadata

Release files for lfp-logging 0.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lfp-logging 0.0.10
File Size Uploaded
lfp_logging-0.0.10.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lfp-logging 0.0.10
File Interpreter ABI Platform
lfp_logging-0.0.10-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / lfp_logging-0.0.10.tar.gz

Download URL lfp_logging-0.0.10.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
295dc4a4d3d1946f02e5ad8b41ffb1bd5b792fb52e740cdad1dd1f293f8280c7
BLAKE2b-256 checksum
How to use checksums
3615d465d4fb1e044ce8a30b427459c8b5279b95f33dd52bddd1bd527a5d2b11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 6, 2026.

Transparency log

Release files / lfp_logging-0.0.10-py3-none-any.whl

Download URL lfp_logging-0.0.10-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4f82233347d9ca7dada421cb3caa22a67c9d301da0fe7e236908c4ed089fbb33
BLAKE2b-256 checksum
How to use checksums
a8475edb27d5e8577e134d744fb0ae360751c035fcfb001d765afa5a6cfdba78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 6, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.10 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page