This project has been archived by its maintainers, and is no longer receiving any updates.
xakki-pylog
Structured JSON logging for Python, compatible with the field and type contract
of xakki/log-laravel and intended for
stdout → fluent-bit → Graylog/GELF pipelines.
The core uses only the Python standard library. Redis and SQLAlchemy support are optional extras.
The release version has one editable source: [project].version in
pyproject.toml. LOGGER_VER reads the installed distribution metadata,
pylog.__version__ aliases it, and every record emits it as extra.log_ver.
Requirements
- Python 3.11+
- No runtime dependencies for the core package
Installation
The package is published on PyPI:
pip install xakki-pylog
# optional integrations
pip install 'xakki-pylog[redis]'
pip install 'xakki-pylog[sqlalchemy]'
The same package name works with other package managers:
uv add xakki-pylog
poetry add xakki-pylog
pdm add xakki-pylog
pipenv install xakki-pylog
Extras use the same syntax, e.g. uv add 'xakki-pylog[redis]'.
To install the unreleased development version straight from Git:
pip install git+https://github.com/xakki/log-python
Quick start
import logging
import pylog
pylog.setup()
logger = logging.getLogger("orders")
logger.info(
"order paid",
extra={"context": {"order_id": "42", "order_money": "19.99"}},
)
order_id is emitted as an integer and order_money as a float according to
the shared context field naming contract. Every record also receives
log_type, file, request_id, stable process metadata and, at warning or
above, a bounded trace.
pylog.setup() configures one idempotent root StreamHandler. It preserves
unrelated handlers and writes one newline-terminated JSON object per event.
Configuration
PylogConfig.from_env() reads a startup snapshot:
| Variable | Purpose | Default |
|---|---|---|
APP_NAME |
extra.app_name |
unset |
APP_ENV |
extra.app_env |
unset |
APP_VERSION |
extra.app_ver |
unset |
LOG_TIER |
extra.tier (web, api, worker, cron) |
unset |
RELEASE_TAG |
release/build id | unset |
RELEASE_TIME |
release time | unset |
LOG_MESSAGE_LIMIT |
source message character limit | 3024 |
LOG_ALLOW_MEMORY |
add process memory fields | false |
LOG_SNAKE_CASE |
normalize context keys before coercion | false |
LOG_CAPTURE_HANDLERS |
install chained uncaught-exception hooks | false |
Boolean parsing accepts 1/true/yes/on and 0/false/no/off (case-insensitive).
Invalid values raise ValueError during configuration instead of silently
changing behavior.
Programmatic configuration:
from pylog import ExtraConfig, PylogConfig, setup
config = PylogConfig(
extra=ExtraConfig(
app_name="orders",
app_env="prod",
app_ver="2026.08.13",
tier="worker",
),
capture_handlers=True,
)
setup(config=config)
Available formatters are JsonFormatter (default), LineFormatter, and
ConsoleFormatter:
pylog.setup(formatter="console", replace=True)
Context and request correlation
Bound context is isolated with contextvars, so concurrent threads and async
tasks do not overwrite one another:
from pylog import bind, bound_context, clear, set_request_id
set_request_id(incoming_request_id)
bind(user_id=7)
with bound_context(order_id=42):
logger.info("order loaded")
clear()
Web middleware can call remote_ip(value). Queue workers should call
reset_request_id() and clear() between jobs.
Exceptions and redaction
Use normal stdlib exception logging:
try:
run_job()
except RuntimeError:
logger.exception("job failed", extra={"context": {"job_id": 42}})
Exception class, sanitized message, code, origin and coalesced trace are emitted
as structured context. Sensitive keys and recognizable Bearer/Basic tokens,
JWTs, key/value credentials and URL passwords are redacted before
serialization. skipTrace can suppress trace collection for a specific event
and is never emitted itself.
When LOG_CAPTURE_HANDLERS=true (or setup enables capture explicitly), pylog
chains the process/thread exception hooks and warnings.showwarning. Uncaught
exceptions get log_type=exception; runtime warnings get log_type=trigger.
Python cannot reliably turn native crashes into structured JSON, so supervisors
and faulthandler remain the fallback for those failures.
Optional integrations
Redis
pylog.handlers.redis.RedisHandler accepts any redis-py-compatible client,
uses LPUSH, and applies LTRIM in the same transaction when cap_size > 0.
It stores exactly the result of its configured formatter, so attach
JsonFormatter (or reuse the formatter installed by pylog.setup()):
from redis import Redis
from pylog.handlers.redis import RedisHandler
handler = RedisHandler(Redis.from_url("redis://localhost"), key="logs", cap_size=10_000)
handler.setFormatter(pylog.JsonFormatter(pylog.PylogConfig.from_env()))
SQLAlchemy
from pylog.integrations.sqlalchemy import install_sqlalchemy_logging
install_sqlalchemy_logging(
engine,
select_threshold_ms=200,
all_threshold_ms=500,
include_bindings=False, # keep disabled in production
)
The integration emits db_table, db_time_ms, db_bindings, sql_type, and
tag=sql. Telescope queries are ignored; long or numerous bindings are not
expanded. Bindings are disabled by default and pass through the secret redactor
before serialization when explicitly enabled.
Worker heartbeat
from pylog import Heartbeat
heartbeat = Heartbeat(logging.getLogger("worker"), name="default", interval=120)
heartbeat.start()
# ...
heartbeat.stop(status=0)
Wire contract
The normative, language-independent specification remains in the reference repository and is not duplicated here:
The JSON formatter provides lowercase level_name, Monolog-compatible numeric
level values (100–600), RFC-3339 timestamps with timezone and
microseconds, canonical app_name/app_env extras, one coalesced trace field,
and iterative UTF-8-aware trimming to the configured wire budget (1400 bytes by
default) without dropping the required process-extra fields.
Development
The repository is Docker-only. Do not run Python tooling directly on the host.
make docker-build
make deps-i
make test # ruff format/check + mypy --strict + pytest
make build
make test-install # uv, Poetry, PDM, Pipenv and pip
Run make help for all targets.
Metadata
Release files for xakki-pylog 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xakki_pylog-0.1.2.tar.gz | 158.1 kB | With provenance | Details for xakki_pylog-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xakki_pylog-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for xakki_pylog-0.1.2-py3-none-any.whl |
Total release size: 220.4 kB
Release files / xakki_pylog-0.1.2.tar.gz
| Download URL | xakki_pylog-0.1.2.tar.gz |
|---|---|
| Size | 158.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5c7da1d358b126c50b5667fc1983b3f3351eb04a027f85d12199a2e742676133
|
|
BLAKE2b-256 checksum How to use checksums |
7cb4a23274da4fba227c37a0c1fef5b06df14a70c6e1bb1f75bad4e14aaa27b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 4, 2026.
Transparency logRelease files / xakki_pylog-0.1.2-py3-none-any.whl
| Download URL | xakki_pylog-0.1.2-py3-none-any.whl |
|---|---|
| Size | 62.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a1ed6b1f85601f357d41be6d1e574fcba13533c46c7323829ea5fb62e1727e40
|
|
BLAKE2b-256 checksum How to use checksums |
690e5432c17dba97c9c7fcd35ac0b46aea23c949f9758a9c76c92e173972c424
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 4, 2026.
Transparency logSecurity for xakki-pylog 0.1.2
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for xakki_pylog-0.1.2.tar.gz
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 Nov 4, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.