loguru-loki-handlers
Handler created for Loguru that sends logs to Grafana Loki in JSON format
Features
- Logs pushed in JSON format
- Custom labels definition
- Allows defining loguru and logger extra keys as labels
- Logger extra keys added automatically as keys into pushed JSON
How to use
from loguru_loki_handler import loki_handler
from loguru import logger
import os
os.environ["LOKI_URL"]="https://USER:PASSWORD@logs-prod-eu-west-0.grafana.net/loki/api/v1/push"
logger.configure(handlers=[{"sink": loki_handler(os.environ["LOKI_URL"],{"application":"Test", "envornment":"Develop"}), "serialize": True}])
logger.info("Starting service")
logger.info("Response code {code} HTTP/1.1 GET {url}", code=200, url="https://loki_handler.io")
Loki messages samples
Without extra
{
"message": "Starting service",
"timestamp": 1681638266.542849,
"process": 48906,
"thread": 140704422327936,
"function": "run",
"module": "test",
"name": "__main__"
}
With extra
{
"message": "Request return 200 HTTP/1.1 GET https://loki_handler.io",
"timestamp": 1681638225.877143,
"process": 48870,
"thread": 140704422327936,
"function": "run",
"module": "test",
"name": "__main__",
"code": 200,
"url": "https://loki_handler.io"
}
Exceptions
{
"message": "name 'plan' is not defined",
"timestamp": 1681638284.358464,
"process": 48906,
"thread": 140704422327936,
"function": "run",
"module": "test",
"name": "__main__",
"file": "test.py",
"path": "/test.py",
"line": 39
}
Loki Query Sample
Loki query sample :
{envornment="Develop"} |= `` | json
Filter by level:
{envornment="Develop", level="INFO"} |= `` | json
Filter by extra:
{envornment="Develop", level="INFO"} |= `` | json | code=`200`
License
The MIT License
Metadata
Release files for loguru-loki-handler 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| loguru-loki-handler-0.1.1.tar.gz | 4.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| loguru_loki_handler-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.4 kB
Release files / loguru-loki-handler-0.1.1.tar.gz
| Download URL | loguru-loki-handler-0.1.1.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
12ee0be4da98a34d2f31a501a2846994ce70859cbdc001616ad3ba852147eee9
|
|
BLAKE2b-256 checksum How to use checksums |
55cbeb08bff76a47f6c208b16eb363055a1cbb7269f19fce72344789de68e149
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / loguru_loki_handler-0.1.1-py3-none-any.whl
| Download URL | loguru_loki_handler-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
61313d4e0b97ace663e3e887e798da785c36acf075968f0aac942685113c5a83
|
|
BLAKE2b-256 checksum How to use checksums |
f7bed548441098ae8953aeb0dfc619acba35560701fa739ad1becaf4a1e4694e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|