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


def as_request_completed():
    smoloki.push_sync(
        {'service': 'web'},
        {'level': 'info', 'event': 'request_completed'},
    )

Usage in Python via client

from smoloki import SmolokiAsyncClient


async def push_via_client():
    async with SmolokiAsyncClient(
        base_endpoint = 'https://example.com',
        headers = {...}
    ) as client:
        await client.push(
            {'service': 'web'},
            {'level': 'info', 'event': 'request_completed'},
        )
        
        # or push in background
        await client.push_in_background(
            {'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.
  • When using SmolokiAsyncClient, the context manager waits for all background tasks to be completed when exiting.

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.1.2.tar.gz (5.6 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.1.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: smoloki-0.1.2.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for smoloki-0.1.2.tar.gz
Algorithm Hash digest
SHA256 05831c57e603ab67c14b6e09ebd1c137e72bc28aae13494a3929e113662f1d0e
MD5 bf1b4339f52f2b2051ae6e942f60e325
BLAKE2b-256 d801c4f8386a1379e04413d8f8ef3563d6e5eefe46e438924de878ea795c78bc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: smoloki-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for smoloki-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a8b4c2c1eb4be1d927671a1505ebb96434e5d7c5f9f7b617a0880d989825d845
MD5 ae74215f3c36f5a9ac4b2ab8f5acd32a
BLAKE2b-256 06ec9b5926e7a7645e6cae54d6b5432fd23f74bee21aeeb8a79e894ae13c90af

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