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->messagerenaming -- JSON output usesmessageinstead ofeventfor 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
loggingalongside 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a603a9a06a9c6411eb58d9962174e6c9f91c8e6410852dcfa8999e7941a6e27
|
|
| MD5 |
a37340715bdfab5b923cda82608a9638
|
|
| BLAKE2b-256 |
2a7102cbc3a4347e82b3a6547a3733b61a8c2a35f406e87bd9e66329f15a247c
|
Provenance
The following attestation bundles were made for albeorla_logging-0.1.1.tar.gz:
Publisher:
publish-logging.yml on albeorla/albeorla-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
albeorla_logging-0.1.1.tar.gz -
Subject digest:
8a603a9a06a9c6411eb58d9962174e6c9f91c8e6410852dcfa8999e7941a6e27 - Sigstore transparency entry: 1154471666
- Sigstore integration time:
-
Permalink:
albeorla/albeorla-python@b5ea5f666f8ab8164f77b69a3a621db54c723471 -
Branch / Tag:
refs/tags/logging-v0.1.1 - Owner: https://github.com/albeorla
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-logging.yml@b5ea5f666f8ab8164f77b69a3a621db54c723471 -
Trigger Event:
push
-
Statement type:
File details
Details for the file albeorla_logging-0.1.1-py3-none-any.whl.
File metadata
- Download URL: albeorla_logging-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cff60386636b21a8432a651b15ccd53ebe2b93321c389de920fa0fc8e8137dd5
|
|
| MD5 |
228bec662fbf6ae1395722f86d141859
|
|
| BLAKE2b-256 |
939343afc9821272fdbd8a9c68f48d907d657333e735f78e9f47fc5e2de7b182
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
albeorla_logging-0.1.1-py3-none-any.whl -
Subject digest:
cff60386636b21a8432a651b15ccd53ebe2b93321c389de920fa0fc8e8137dd5 - Sigstore transparency entry: 1154471667
- Sigstore integration time:
-
Permalink:
albeorla/albeorla-python@b5ea5f666f8ab8164f77b69a3a621db54c723471 -
Branch / Tag:
refs/tags/logging-v0.1.1 - Owner: https://github.com/albeorla
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-logging.yml@b5ea5f666f8ab8164f77b69a3a621db54c723471 -
Trigger Event:
push
-
Statement type: