skillfed

loki-logger-handler

Handler designed for transmitting logs to Grafana Loki in JSON format.

loki-logger-handler v1.1.2 122.7K downloads/30d#11,936 on PyPI55
Permissive license MIT AGING released

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-handler

uv

uv add loki-logger-handler

poetry

poetry add loki-logger-handler

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

grafana loki logging handlersend logs to lokipython logging to lokiloki json log handlergrafana loki integrationstructured logging lokilog aggregation handler
logginggrafana-lokilog-aggregation

More Monitoring packages

tqdm

Wraps any iterable to display a real-time…

copyleft · top 100 on PyPI

opentelemetry-semantic-conventions

Provides generated Python code for…

permissive · top 100 on PyPI

opentelemetry-sdk

Provides the reference implementation of the…

permissive · top 100 on PyPI

opentelemetry-api

Provides the abstract API and interfaces for…

permissive · top 100 on PyPI

opentelemetry-exporter-otlp-proto-http

Exports OpenTelemetry observability data to an…

permissive · top 1,000 on PyPI

opentelemetry-instrumentation

Provides automatic instrumentation commands and…

permissive · top 1,000 on PyPI

libadvian

Provides a collection of small utility helpers…

permissive · top 15,000 on PyPI

loguru

Loguru provides a pre-configured logger that…

permissive · top 1,000 on PyPI

python-logging-loki

A Python logging handler that sends log records…

permissive · top 5,000 on PyPI

logger

A Python logging helper that provides utilities…

unclear · top 15,000 on PyPI

python-json-logger

Formats Python logging output as JSON, making…

permissive · top 1,000 on PyPI

splunk-hec-handler

Integrates Python logging with Splunk's HTTP…

permissive · top 15,000 on PyPI

pygelf

Provides Python logging handlers that send log…

permissive · top 15,000 on PyPI

cloudwatch

A Python logging handler that sends log events…

permissive · top 15,000 on PyPI

mcp-grafana

An MCP server that exposes Grafana dashboards,…

permissive · top 15,000 on PyPI

coralogix-logger

Sends Python application logs to Coralogix, a…

permissive · top 5,000 on PyPI