Skip to main content

Python logging handler for Grafana Loki.

Project description

loki-handler

PyPI version License CircleCI

Python logging handler for Loki.
https://grafana.com/loki

Backport of Andrey Maslov's python-logging-loki for Python 2.X.

Installation

pip install loki-handler

Usage

import logging
import loki_handler


handler = loki_handler.LokiHandler(
    url="https://my-loki-instance/loki/api/v1/push", 
    tags={"application": "my-app"},
    auth=("username", "password"),
    version="1",
)

logger = logging.getLogger("my-logger")
logger.addHandler(handler)
logger.error(
    "Something happened", 
    extra={"tags": {"service": "my-service"}},
)

Example above will send Something happened message along with these labels:

  • Default labels from handler
  • Message level as serverity
  • Logger's name as logger
  • Labels from tags item of extra dict

The given example is blocking (i.e. each call will wait for the message to be sent).

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

loki-handler-0.1.1.tar.gz (6.2 kB view details)

Uploaded Source

File details

Details for the file loki-handler-0.1.1.tar.gz.

File metadata

  • Download URL: loki-handler-0.1.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.7.0 requests/2.23.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/2.7.17

File hashes

Hashes for loki-handler-0.1.1.tar.gz
Algorithm Hash digest
SHA256 69bb3a27bff49adcfb974494349060f9763bc9839ef19cc50eb77c3657d4b7cd
MD5 c5ca2fc257c15dec66b46a2b74cb3890
BLAKE2b-256 93fad24eee108ddf340d44ec4b381d056b569bfefc92883e19f63f48b5eb11ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page