Skip to main content

The LokiAssistant lib is a small tool to push logging to Loki server.

Project description

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")

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

loki-assistant-0.0.2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

loki_assistant-0.0.2-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file loki-assistant-0.0.2.tar.gz.

File metadata

  • Download URL: loki-assistant-0.0.2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for loki-assistant-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ec4824f26ef2f0c970e3d273fbca2dd96fdaaeed38d3a340406687a24b20f506
MD5 ef10641fd9314757ed39b1e7f4233d4d
BLAKE2b-256 6763e305207dc175e978a03a9badc9ddb700ee54efb2ede1bc96385d5de25031

See more details on using hashes here.

File details

Details for the file loki_assistant-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for loki_assistant-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5b1f3ad680a86e3685cc62b86c43e70eb79cdf107ab76a7393c9b56e4597caf9
MD5 0f4b6b067679cbf7023e1e4446016215
BLAKE2b-256 f958b72b57fb4bc88caaa046b6393d758a414880851966414cce516ac68ada72

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page