loki-logger-handler
Handler designed for transmitting logs to Grafana Loki in JSON format.
What it is and what it does
loki-logger-handler is a Python logging handler that bridges the standard logging module (and optionally loguru) to Grafana Loki, a log aggregation system. It formats log messages as JSON, attaches custom labels for filtering and querying, and sends them to a Loki server in batches, optionally compressed. The handler automatically includes log metadata like timestamps, process IDs, thread IDs, and function names; you can also attach custom fields via logging extras, which become searchable keys in the JSON payload.
The package supports both Python's built-in logging and the loguru library, with separate formatters for each. It includes options for basic authentication, custom headers, configurable timeouts, and Loki 3.0 structured metadata. Logs are buffered and flushed either when the buffer fills or after a timeout, reducing network overhead. The handler runs as a background thread, so it does not block your application.
Use it for:
- Centralize application logs from multiple Python services into a single Loki instance for unified querying and monitoring.
- Add structured metadata (user IDs, trace IDs, request codes) to logs for filtering and correlation in Grafana dashboards.
- Replace file-based logging with cloud-native log aggregation in containerized or serverless deployments.
- Batch and compress logs before sending to reduce network bandwidth and Loki ingestion costs.
- Integrate loguru-based applications with Loki without rewriting logging code.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A logging handler that sends Python log messages to Grafana Loki in JSON format, with support for custom labels, batch publishing, and compression.
Yes, if you are already running Grafana Loki and need a straightforward Python logging integration. The package has no runtime dependencies, low install friction, and a permissive license. However, note that maintenance is aging (last update 2025-05-26, last commit 2026-01-09); if you require active support or plan to use Loki 3.0 structured metadata in production, verify compatibility first or be prepared to maintain a fork.
Install
loki-logger-handler on PyPI
pip
pip install loki-logger-handleruv
uv add loki-logger-handlerpoetry
poetry add loki-logger-handlerInstalling loki-logger-handler
Before you install
Low install friction with no runtime dependencies. Maintenance status is aging—last commit was 2026-01-09 and the package has not been updated since 2025-05-26, so expect slower response to issues or feature requests.
License in practice
MIT license is permissive; you can use this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install loki-logger-handler
from loki_logger_handler.loki_logger_handler import LokiLoggerHandler
import logging
import os
logger = logging.getLogger("app")
logger.setLevel(logging.DEBUG)
handler = LokiLoggerHandler(
url=os.environ["LOKI_URL"],
labels={"application": "MyApp"},
timeout=10,
)
logger.addHandler(handler)
logger.info("Test message")
Requires a Grafana Loki server endpoint URL, typically provided via environment variable LOKI_URL in the format https://user:password@host/loki/api/v1/push.
Verify before relying
- Whether loguru integration works reliably with all loguru versions and configurations.
- Performance characteristics when sending high-volume logs or with large batch sizes.
- Compatibility with Loki 3.0 structured metadata features in production environments.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=2.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | aging — 445 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 122,742/month — #11,936 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: loki_logger_handler-1.1.2-py3-none-any.whl
Keywords: loki, loguru, logging, logger, handler
Tags
More Monitoring packages
Wraps any iterable to display a real-time…
copyleft · top 100 on PyPI
opentelemetry-semantic-conventionsProvides generated Python code for…
permissive · top 100 on PyPI
opentelemetry-sdkProvides the reference implementation of the…
permissive · top 100 on PyPI
opentelemetry-apiProvides the abstract API and interfaces for…
permissive · top 100 on PyPI
opentelemetry-exporter-otlp-proto-httpExports OpenTelemetry observability data to an…
permissive · top 1,000 on PyPI
opentelemetry-instrumentationProvides automatic instrumentation commands and…
permissive · top 1,000 on PyPI
libadvianProvides a collection of small utility helpers…
permissive · top 15,000 on PyPI
loguruLoguru provides a pre-configured logger that…
permissive · top 1,000 on PyPI
python-logging-lokiA Python logging handler that sends log records…
permissive · top 5,000 on PyPI
loggerA Python logging helper that provides utilities…
unclear · top 15,000 on PyPI
python-json-loggerFormats Python logging output as JSON, making…
permissive · top 1,000 on PyPI
splunk-hec-handlerIntegrates Python logging with Splunk's HTTP…
permissive · top 15,000 on PyPI
pygelfProvides Python logging handlers that send log…
permissive · top 15,000 on PyPI
cloudwatchA Python logging handler that sends log events…
permissive · top 15,000 on PyPI
mcp-grafanaAn MCP server that exposes Grafana dashboards,…
permissive · top 15,000 on PyPI
coralogix-loggerSends Python application logs to Coralogix, a…
permissive · top 5,000 on PyPI