Skip to main content

Ultra-performant Loki logger for Python applications (asyncio + aiohttp)

Project description

Loki Console Logger for Python 🚀

PyPI version Python versions License

A high-performance console logger for Python that automatically sends all print, logging, exceptions, and custom events to Grafana Loki — using fully asyncio + aiohttp.
Ideal for observability, real-time debugging, and log aggregation in microservices or modern async applications.


✨ Features

  • 🚀 Fully asynchronous (non-blocking) sending with aiohttp
  • 🧠 Dynamic and static labels per log stream
  • 🧹 Batching and auto-flush for high throughput
  • 💥 Captures all print() calls, logging messages and unhandled exceptions
  • 🔥 Lightweight, zero external dependencies (only aiohttp)
  • 🛡️ Robust error handling, resilient to network failures

📦 Installation

pip install loki-console-logger-python

🚀 Quickstart

from loki_console_logger_python import LokiLogger
from loki_console_logger_python.config import LokiLoggerOptions

options = LokiLoggerOptions(
    url="https://loki.elvenobservability.com/loki/api/v1/push",
    tenant_id="your-tenant-id",
    app_name="your-application",
    auth_token="your-optional-token",
    batch_size=10,             # Optional (default 10)
    flush_interval=2,          # Optional (default 2 seconds)
    labels={"env": "production"},
    dynamic_labels={"hostname": lambda: "server-001"},
)

logger = LokiLogger(options)

# Track custom events
logger.track_event("user_signup", {"user_id": 123})

# Capture print automatically
print("Hello from Python!")

# Capture uncaught exceptions automatically
raise Exception("Test error!")

⚙️ Configuration Options

Option Description Default
url URL to Loki HTTP Push API
tenant_id X-Scope-OrgID for multi-tenancy
app_name Application name label
auth_token Bearer token for authorization None
batch_size Max events before flushing 10
flush_interval Max time (seconds) before flushing 2
labels Fixed labels per stream {}
dynamic_labels Dynamic labels (functions) {}

🤝 Contributing

Contributions are welcome! Feel free to open issues, submit pull requests, or suggest new features.

Let's make observability in Python faster and better! 🚀

  1. Fork this repo
  2. Create a feature branch
  3. Submit a PR!

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


Created with ❤️ by Leonardo Zwirtes

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_logger_async-1.0.2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

loki_logger_async-1.0.2-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file loki_logger_async-1.0.2.tar.gz.

File metadata

  • Download URL: loki_logger_async-1.0.2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for loki_logger_async-1.0.2.tar.gz
Algorithm Hash digest
SHA256 6da74e78a4bc8bf8c516258c4717a8353b70bb9aa19fc39bb57150dfa9ef9dd3
MD5 9b45dc760dc0d2bca4d549c14f8cc64b
BLAKE2b-256 ef1876bb46ee9f80c935b5d4cff7016fa0b0203dcb3b70f0e0c10d99a95b16c4

See more details on using hashes here.

File details

Details for the file loki_logger_async-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for loki_logger_async-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ecc5c3967c9bd7062924c11255648eb2e807f310dccae6da4b84bb9d63877b26
MD5 091742de1845a6bdfd1b5ca32566fce5
BLAKE2b-256 9f006fc8d75fa384f5c0489fe0f0b00d7a851be689d8ca7a9390d0724e8735b6

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