Skip to main content

Loki Assistant

Build PyPi version License: MIT PyPI pyversions PyPI status

The Loki Assistant has been created to send log messages to the LOKI server. The labels can be specified individually.

Install

You can install this package with pip tool from https://pypi.org/.

pip install loki-assistant

Usage

There are three ways to send messages to the server.

Each message individually

Sending every single message takes a lot of time. 6000 messages takes 3.67 s to send.

from datetime import datetime
from loki_assistant import LokiAssistant

loki = LokiAssistant('http://localhost:3100/loki/api/v1/push', primary_tags={"application": "test"})

loki.post(loki.LogLevels.VERBOSE, {"thread": "1"}, datetime.now(), f"messsage: DEBUG")
loki.post(loki.LogLevels.DEBUG, {"thread": "1"}, datetime.now(), f"message: DEBUG")
loki.post(loki.LogLevels.INFO, {"thread": "1"}, datetime.now(), f"message: INFO")
loki.post(loki.LogLevels.WARNING, {"thread": "1"}, datetime.now(), f"message: WARNING")
loki.post(loki.LogLevels.ERROR, {"thread": "1"}, datetime.now(), f"message: ERROR")
loki.post(loki.LogLevels.FATAL, {"thread": "1"}, datetime.now(), f"message: FATAL")

Collect messages

If several messages are sent together, a lot of time can be saved and the performance can be increased. Sending 60000 messages takes 0.660 s.

Push all together

from datetime import datetime
from loki_assistant import LokiAssistant

loki = LokiAssistant('http://localhost:3100/loki/api/v1/push', primary_tags={"application": "test"})

loki.commit(loki.LogLevels.VERBOSE, {"thread": "1"}, datetime.now(), f"messsage: DEBUG")
loki.commit(loki.LogLevels.DEBUG, {"thread": "1"}, datetime.now(), f"message: DEBUG")
loki.commit(loki.LogLevels.INFO, {"thread": "1"}, datetime.now(), f"message: INFO")
loki.commit(loki.LogLevels.WARNING, {"thread": "1"}, datetime.now(), f"message: WARNING")
loki.commit(loki.LogLevels.ERROR, {"thread": "1"}, datetime.now(), f"message: ERROR")
loki.commit(loki.LogLevels.FATAL, {"thread": "1"}, datetime.now(), f"message: FATAL")

loki.push()

Push them over a time interval.

from datetime import datetime
from loki_assistant import LokiAssistant

loki = LokiAssistant('http://localhost:3100/loki/api/v1/push', primary_tags={"application": "test"}, push_interval=1)

loki.commit(loki.LogLevels.VERBOSE, {"thread": "1"}, datetime.now(), f"messsage: DEBUG")
loki.commit(loki.LogLevels.DEBUG, {"thread": "1"}, datetime.now(), f"message: DEBUG")
loki.commit(loki.LogLevels.INFO, {"thread": "1"}, datetime.now(), f"message: INFO")
loki.commit(loki.LogLevels.WARNING, {"thread": "1"}, datetime.now(), f"message: WARNING")
loki.commit(loki.LogLevels.ERROR, {"thread": "1"}, datetime.now(), f"message: ERROR")
loki.commit(loki.LogLevels.FATAL, {"thread": "1"}, datetime.now(), f"message: FATAL")

Release files for loki-assistant 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for loki-assistant 0.0.2
File Size Uploaded
loki-assistant-0.0.2.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for loki-assistant 0.0.2
File Interpreter ABI Platform
loki_assistant-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size:8.7 kB

Release files / loki-assistant-0.0.2.tar.gz

Download URL loki-assistant-0.0.2.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ec4824f26ef2f0c970e3d273fbca2dd96fdaaeed38d3a340406687a24b20f506
BLAKE2b-256 checksum
How to use checksums
6763e305207dc175e978a03a9badc9ddb700ee54efb2ede1bc96385d5de25031
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / loki_assistant-0.0.2-py3-none-any.whl

Download URL loki_assistant-0.0.2-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b1f3ad680a86e3685cc62b86c43e70eb79cdf107ab76a7393c9b56e4597caf9
BLAKE2b-256 checksum
How to use checksums
f958b72b57fb4bc88caaa046b6393d758a414880851966414cce516ac68ada72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page