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

Uploaded Source

Built Distribution

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

Uploaded Python 3

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