Skip to main content

Environment-driven configuration for Python’s standard library `logging` module.

Project description

logging-blueprint

Environment-driven configuration for Python’s standard library logging module.

Overview

logging-blueprint is a small, stdlib-first library for configuring Python’s built-in logging module using environment variables.

The library is designed to be:

  • Drop-in — integrates directly with logging.config.dictConfig
  • Environment-driven — inspired by Rust’s env_logger ergonomics
  • Non-invasive — augments existing logging configurations instead of replacing them
  • Strictly typed — intended for use in modern, typed Python codebases

logging-blueprint does not introduce a new logging framework. It exists solely to make configuration of the standard library logging system easier, more composable, and more production-friendly.

Installation

pip install logging-blueprint

(Exact installation instructions may change depending on distribution method.)

Quick Start

import logging_blueprint

logging_blueprint.apply_env_logging()

This reads logging configuration from environment variables and applies it directly to Python’s standard library logging system.

Examples

Run the demo scripts with uv run to see the library in action:

  • uv run python examples/basic_quickstart.py — minimal quick start using env-driven config
  • PY_LOG_STREAM=stdout PY_LOG_STYLE=plain uv run python examples/devops_cli_demo.py — DevOps-style CLI mixing stdout and logs
  • PY_LOG=debug PY_LOG_STREAM=stdout PY_LOG_STYLE=plain uv run python examples/asgi_app_demo.py — tiny ASGI app emitting request lifecycle logs

Environment Variables

The following environment variables are supported:

Variable Description
PY_LOG Logging directives (e.g. info,myapp=debug)
PY_LOG_STYLE Output style (plain, pretty, logfmt, json, auto)
PY_LOG_STREAM Output stream (stdout or stderr)
PY_LOG_FMT Log format string (plain/pretty/logfmt styles)
PY_LOG_DATEFMT Datetime format string
PY_LOG_DISABLE_EXISTING Disable existing loggers (1 or 0)

Exact semantics and defaults are documented in the API reference.

Rust-Style Logging Directives

PY_LOG follows a Rust-inspired directive format:

info,myapp=debug,myapp.db=warning
  • A bare level sets the default/root log level
  • module=level entries override specific loggers
  • Later directives override earlier ones

This maps directly onto Python logger names.

Using With Existing dictConfig / YAML

logging-blueprint is designed to work alongside existing logging configurations.

import logging.config
import logging_blueprint

base_config = {
    # existing dictConfig-style configuration
}

config = logging_blueprint.merge_env_into_dict_config(base_config)
logging.config.dictConfig(config)

This allows environment variables to override or extend static configurations without duplicating configuration logic.

API Overview

Core Entry Points

apply_env_logging(...)
build_dict_config_from_env(...)
merge_env_into_dict_config(...)

Parsing Utilities

EnvLoggingConfig.from_env(...)
parse_directives(...)

All public APIs are strictly typed.

Output Styles

logging-blueprint supports multiple output styles:

  • plain — standard logging.Formatter
  • pretty — human-readable output with ANSI colors and extras
  • logfmt — key=value output with extras, colorized on TTY
  • json — structured JSON suitable for log aggregation
  • auto — selects an appropriate style based on environment

Exact formatting behavior is intentionally minimal and configurable.

Design Goals

  • Use the Python standard library wherever possible
  • Avoid hidden global state
  • Avoid opinionated logging frameworks
  • Preserve compatibility with existing logging setups
  • Be explicit, inspectable, and boring in production

Non-Goals

  • Replacing Python’s logging system
  • Introducing a new logging API
  • Providing transport, filtering, or routing beyond stdlib capabilities

Compatibility

  • Python: v3.10+

Development Status

This project is currently:

  • ☑ Experimental
  • ☐ Beta
  • ☐ Stable

APIs may change until a stable release is declared.

Contributing

Contribution guidelines, development setup, and code style are documented in: CONTRIBUTING.md.

License

Licensed under the MIT License.

See LICENSE for details.

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

logging_blueprint-0.0.1.tar.gz (60.5 kB view details)

Uploaded Source

Built Distribution

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

logging_blueprint-0.0.1-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file logging_blueprint-0.0.1.tar.gz.

File metadata

  • Download URL: logging_blueprint-0.0.1.tar.gz
  • Upload date:
  • Size: 60.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.5

File hashes

Hashes for logging_blueprint-0.0.1.tar.gz
Algorithm Hash digest
SHA256 88218a5e0b26f79064831231a73a7d350f554ed5d60afaf716ff88256988658d
MD5 48f7f0702d335d716e20c2150a3a3a06
BLAKE2b-256 e0dee17c80e559f10633d336a9c6faa45ce983103917b5c34f93abc581a61e48

See more details on using hashes here.

File details

Details for the file logging_blueprint-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for logging_blueprint-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cb8c41cf65dc872ee0eb2648da7d1daf90aa02f86db69442c8219ece9adfb698
MD5 e94613b6fa0cd2677f03e401d7afc013
BLAKE2b-256 1bdbc4882da80087c3092bf5a99e1ff43525e51a8e2acd4a53851bcbbe87b0bc

See more details on using hashes here.

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