Production-grade logs interceptor for Python with Loki transport, resilience, batching, and framework integrations.
Project description
elven-logs-interceptor-python
High-performance, production-ready log interceptor for Python with Loki transport, batching, compression, circuit breaker, DLQ, and framework integrations.
Installation
pip install elven-logs-interceptor-python
With all extras:
pip install "elven-logs-interceptor-python[all]"
Quick Start
from logs_interceptor import init, logger
init(
{
"appName": "billing-service",
"interceptConsole": True,
"transport": {
"url": "https://loki.example.com/loki/api/v1/push",
"tenantId": "tenant-a",
"authToken": "token",
"compression": "gzip",
},
}
)
logger.info("service started", {"port": 3000})
Environment Variables
The package supports all LOGS_* variables from the JS v3 design.
Required:
LOGS_URLLOGS_TENANTLOGS_APP_NAME
Core:
LOGS_TOKENLOGS_APP_VERSIONLOGS_ENVIRONMENT
Transport:
LOGS_COMPRESSION(none|gzip|brotli|snappy)LOGS_COMPRESSION_LEVELLOGS_COMPRESSION_THRESHOLDLOGS_USE_WORKERSLOGS_MAX_WORKERSLOGS_WORKER_TIMEOUTLOGS_CONNECTION_POOLINGLOGS_MAX_SOCKETSLOGS_TIMEOUTLOGS_MAX_RETRIESLOGS_RETRY_DELAY
Buffer:
LOGS_BUFFER_MAX_SIZELOGS_BUFFER_FLUSH_INTERVALLOGS_BUFFER_MAX_MEMORY_MBLOGS_BUFFER_MAX_AGELOGS_BUFFER_AUTO_FLUSH
Filter:
LOGS_FILTER_LEVELSLOGS_FILTER_SAMPLING_RATELOGS_FILTER_SANITIZELOGS_FILTER_MAX_MESSAGE_LENGTH
Circuit Breaker:
LOGS_CIRCUIT_BREAKER_ENABLEDLOGS_CIRCUIT_BREAKER_FAILURE_THRESHOLDLOGS_CIRCUIT_BREAKER_RESET_TIMEOUTLOGS_CIRCUIT_BREAKER_HALF_OPEN_REQUESTS
DLQ:
LOGS_DLQ_ENABLEDLOGS_DLQ_TYPE(memory|file)LOGS_DLQ_MAX_SIZELOGS_DLQ_MAX_RETRIESLOGS_DLQ_BASE_PATH
Runtime:
LOGS_MAX_CONCURRENT_FLUSHESLOGS_INTERCEPT_CONSOLELOGS_PRESERVE_ORIGINAL_CONSOLELOGS_ENABLE_METRICSLOGS_ENABLE_HEALTH_CHECKLOGS_DEBUGLOGS_SILENT_ERRORSLOGS_ENABLEDLOGS_AUTO_INITLOGS_ENABLE_EXPERIMENTAL_PROTOBUF(optional, enables experimental snappy/protobuf transport path)
Labels:
- Prefix
LOGS_LABEL_*(example:LOGS_LABEL_SERVICE=billing)
Public API
init(config)get_logger()is_initialized()destroy()adestroy()loggerproxy withdebug/info/warn/error/fatal/log/track_event/flush/aflush/get_metrics/get_health/destroy/adestroy/with_context/with_context_async
Python import remains:
import logs_interceptor
Integrations
- Python
logging(LoggingHandler) - FastAPI / Starlette (
FastAPIMiddleware) - Django (
DjangoMiddleware) - Flask (
FlaskExtension) - Celery (
CelerySignals) - structlog (
StructlogProcessor) - loguru (
LoguruSink)
Auto Init
Set LOGS_AUTO_INIT=true and import the package.
Preload mode:
python -m logs_interceptor.preload
Development
pip install -e ".[dev]"
ruff check .
mypy src
pytest
Deploy / Publish
Local publish script:
./scripts/publish.sh --repository testpypi --dry-run
./scripts/publish.sh --repository testpypi
./scripts/publish.sh --repository pypi
Token environment variables used by default:
TEST_PYPI_API_TOKENfor--repository testpypiPYPI_API_TOKENfor--repository pypi
Optional script flags:
--skip-checks(skip lint/type/test)--skip-build(skip build/twine check)--token-env CUSTOM_VAR(custom token env var name)--no-skip-existing(upload fails if version already exists)
Makefile shortcuts:
make qa
make publish-dry-run
make publish-testpypi
make publish-pypi
GitHub Actions publish workflow:
- File:
.github/workflows/publish.yml - Trigger: manual (
workflow_dispatch) - Inputs:
repository = testpypi | pypi - Required secrets:
TEST_PYPI_API_TOKENPYPI_API_TOKEN
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
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 elven_logs_interceptor_python-0.1.2.tar.gz.
File metadata
- Download URL: elven_logs_interceptor_python-0.1.2.tar.gz
- Upload date:
- Size: 50.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5beabc768b38fe093fb56dc85d673768cee04743cca2358c318be7c1c66f87f8
|
|
| MD5 |
b1f6075a1411c265ec538185aa8fc1b8
|
|
| BLAKE2b-256 |
e84b80263db7fb6bc241144309981b6de1c608af9eccf2eade6ca08b1a902518
|
File details
Details for the file elven_logs_interceptor_python-0.1.2-py3-none-any.whl.
File metadata
- Download URL: elven_logs_interceptor_python-0.1.2-py3-none-any.whl
- Upload date:
- Size: 55.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5dcb3aa167e791ce1a9cbd47375c93c148ffb728a3adcc1cc329d98b215cf5c
|
|
| MD5 |
ccd5c80cf910310cafbbb2bc8cef972f
|
|
| BLAKE2b-256 |
6e90f9f333154c93a7e89c30e1defc0d66ecbc2207554d2fa713b9d42802eedd
|