Skip to main content

Tiny library to push logs to `Grafana Loki` in `logfmt` format.

Project description

smoloki

PyPI version npm version

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 using logging.
  • 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


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.19.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smoloki-0.0.19-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file smoloki-0.0.19.tar.gz.

File metadata

  • Download URL: smoloki-0.0.19.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for smoloki-0.0.19.tar.gz
Algorithm Hash digest
SHA256 82ac1951340fd0940711a87ddd3e18748791e16fffd3a3c2862273b38310de10
MD5 63c622de1bd5327965622a5788cad73a
BLAKE2b-256 81626f367d18ad4e646f3dfab7dae2fdbd8a17ad4ea03d69cf1a11acb9420b9c

See more details on using hashes here.

File details

Details for the file smoloki-0.0.19-py3-none-any.whl.

File metadata

  • Download URL: smoloki-0.0.19-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for smoloki-0.0.19-py3-none-any.whl
Algorithm Hash digest
SHA256 4fca1e309160134e6f6e3243ddbf8a777c41035fbda7a22934bc6c0a7eeaebd9
MD5 a0d8203ad61f1c71ea3e04d657c7749d
BLAKE2b-256 153ce734fdecf91cf5cedab6637812535c4351f2d3421946c0a47f173f7e5843

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