Skip to main content

A simple, zero-dependency lazy-initialization logging utility

Project description

lfp-logging

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

Features

  • Zero Dependencies: Built entirely on the Python standard library.
  • 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).
  • LOG_FORMAT_DATE: Custom date format (default: %Y-%m-%d %H:%M:%S).
  • LOG_FORMAT_COLOR: Global ANSI color code for all levels.
  • 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.

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

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

lfp_logging-0.0.3.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

lfp_logging-0.0.3-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file lfp_logging-0.0.3.tar.gz.

File metadata

  • Download URL: lfp_logging-0.0.3.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lfp_logging-0.0.3.tar.gz
Algorithm Hash digest
SHA256 e27945647b550721cd81eb1c51cac3eb3e14817a02a13c4093da921eda43192f
MD5 9504afa5de55fb44490af865143ed37b
BLAKE2b-256 def70ecf81adabc648725f30d17660ecc80d3fb58fe2ef8c31985e2aefba67d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for lfp_logging-0.0.3.tar.gz:

Publisher: publish.yml on regbo/lfp-logging-py

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

File details

Details for the file lfp_logging-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: lfp_logging-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for lfp_logging-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9317d006c2d083c5bb7268fec2b7efdcd06750fe5f22ffc8a54e9a31879174c4
MD5 98b5cf33f393b3da494502aaa37135e0
BLAKE2b-256 a32486593816b56e881b0939f6f38ec3cb0bdc8d7e426626e6b5a267b95ade4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for lfp_logging-0.0.3-py3-none-any.whl:

Publisher: publish.yml on regbo/lfp-logging-py

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