Skip to main content

Structured logging helpers for Python apps

Project description

albeorla-logging

Opinionated, reusable structlog configuration for Python applications. Get structured logging with sensible defaults in two lines of code.

Features

  • JSON or console output -- switch between machine-readable JSON and human-friendly colored console output with a single flag
  • ISO 8601 UTC timestamps -- every log event is stamped automatically
  • event -> message renaming -- JSON output uses message instead of event for compatibility with log aggregators (Datadog, ELK, etc.)
  • Bound context -- attach key-value context (service name, component, request ID) to a logger once; it appears on every subsequent event
  • stdlib integration -- configures Python's logging alongside structlog so third-party library logs are captured too

Install

pip install "albeorla-logging @ git+ssh://git@github.com/albeorla/albeorla-logging.git"

Or pin to a version:

pip install "albeorla-logging @ git+ssh://git@github.com/albeorla/albeorla-logging.git@v0.1.0"

With uv:

uv add "albeorla-logging @ git+ssh://git@github.com/albeorla/albeorla-logging.git"

Quick start

import logging
from albeorla_logging import configure_logging, get_logger

# Call once at startup
configure_logging(json_output=True, level=logging.INFO)

# Get a logger with optional bound context
log = get_logger(__name__, component="api")

log.info("service_started", port=8080)
# => {"message": "service_started", "component": "api", "port": 8080, "level": "info", "timestamp": "2026-03-20T12:00:00Z", ...}

Console output

configure_logging(json_output=False, level=logging.DEBUG)
log = get_logger("myapp")
log.debug("ready")
# => 2026-03-20T12:00:00Z [debug] ready  logger_name=myapp

API

configure_logging(json_output=False, level=logging.INFO)

Configure structlog and stdlib logging for the process. Call once at application startup.

Parameter Type Default Description
json_output bool False Emit JSON (True) or colored console output (False)
level int logging.INFO Minimum log level

get_logger(name=None, **initial_context)

Return a structlog.stdlib.BoundLogger. Any keyword arguments are permanently bound as context.

Parameter Type Default Description
name str | None None Logger name (typically __name__)
**initial_context Any -- Key-value pairs bound to every log event

Requirements

  • Python >= 3.10
  • structlog >= 24.1.0

License

MIT

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

albeorla_logging-0.1.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

albeorla_logging-0.1.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for albeorla_logging-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8a603a9a06a9c6411eb58d9962174e6c9f91c8e6410852dcfa8999e7941a6e27
MD5 a37340715bdfab5b923cda82608a9638
BLAKE2b-256 2a7102cbc3a4347e82b3a6547a3733b61a8c2a35f406e87bd9e66329f15a247c

See more details on using hashes here.

Provenance

The following attestation bundles were made for albeorla_logging-0.1.1.tar.gz:

Publisher: publish-logging.yml on albeorla/albeorla-python

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

File details

Details for the file albeorla_logging-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for albeorla_logging-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cff60386636b21a8432a651b15ccd53ebe2b93321c389de920fa0fc8e8137dd5
MD5 228bec662fbf6ae1395722f86d141859
BLAKE2b-256 939343afc9821272fdbd8a9c68f48d907d657333e735f78e9f47fc5e2de7b182

See more details on using hashes here.

Provenance

The following attestation bundles were made for albeorla_logging-0.1.1-py3-none-any.whl:

Publisher: publish-logging.yml on albeorla/albeorla-python

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