Skip to content

cuerty/loki-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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).

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages