Tiny library to push logs to `Grafana Loki` in `logfmt` format.
Project description
smoloki
Tiny library to push logs to Grafana Loki
in logfmt
format.
CLI
usage: smoloki [-h] [-b BASE_ENDPOINT] [-H HEADERS] labels information
cli for pushing to loki
positional arguments:
labels json-encoded string with labels
information json-encoded string with information
optional arguments:
-h, --help show this help message and exit
-b BASE_ENDPOINT base address of loki server
-H HEADERS json-encoded string with headers for request to loki server
Usage in Python
import smoloki
async def as_request_completed():
await smoloki.push(
{'service': 'web'},
{'level': 'info', 'event': 'request_completed'},
)
def as_request_completed():
smoloki.push_sync(
{'service': 'web'},
{'level': 'info', 'event': 'request_completed'},
)
Usage in NodeJS
const smoloki = require('smoloki');
async function as_request_completed() {
await smoloki.push({ service: 'web' }, { level: 'info', event: 'request_completed' });
}
Implementation details
- Calls to
push
method will never throw. Any exception will just be logged usinglogging
. - Keys in labels and information must be strings. If
None
is provided as value in case of python, it will be serialized as empty string. - Values in labels and information must be string, integers or floats.
- If no
base_endpoint
provided (using parameter or env), nothing will happen.
Configuration
SMOLOKI_BASE_ENDPOINT
– base address of loki server.SMOLOKI_HEADERS
- headers for request to loki server (can be used for authorization).SMOLOKI_BASE_LABELS
- base labels that will be added to logs.SMOLOKI_BASE_INFORMATION
- base information that will be added to logs.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
smoloki-0.0.17.tar.gz
(4.7 kB
view details)
Built Distribution
File details
Details for the file smoloki-0.0.17.tar.gz
.
File metadata
- Download URL: smoloki-0.0.17.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9199f4558235e8434a33b8a7d3a15bd13fc060a3df28bc1bcc33fbd56a8eea12 |
|
MD5 | 8fe62bbd8fd6573564e6bf2f41c18fa0 |
|
BLAKE2b-256 | 361b5dca9a7582a8f8c2362b8250552d6531b0ed6abea37b47730be305cbc286 |
File details
Details for the file smoloki-0.0.17-py3-none-any.whl
.
File metadata
- Download URL: smoloki-0.0.17-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 080f00a8f3f32c46bd40e4b5d7bef2c269d34d12bd3f9f50b340f7e0cd1ee23b |
|
MD5 | 9b742f6823832973fbefce18525278ab |
|
BLAKE2b-256 | 2b3aa26ee8e64edd2e6a0d3ca3ade1c302106bfa4235ae05d52f53b8b793c3de |