Lognitor SDK for Python — log management, error tracking, and monitoring
Project description
lognitor
Official Lognitor SDK for Python — log management, error tracking, and monitoring.
Install
pip install lognitor
Quick Start
import lognitor
lognitor.init(api_key="lgn_...", service="api-server", environment="production")
lognitor.info("Server started", metadata={"port": 8000})
Configuration
All config is passed to init(). See docstring for full options.
Logging
lognitor.debug("Cache hit", metadata={"key": "users:123"})
lognitor.info("User signed in", tags=["auth"])
lognitor.warn("Slow query", perf={"duration_ms": 3200})
lognitor.error("Payment failed", notify=True)
lognitor.fatal("Database unreachable")
Error Tracking
try:
process_order(order)
except Exception as exc:
event_id = lognitor.capture_exception(exc)
Uncaught exceptions captured automatically via sys.excepthook.
stdlib logging Integration
import logging
handler = lognitor.LogHandler(level=logging.WARNING)
logging.getLogger().addHandler(handler)
Framework Integrations
Django
# settings.py
MIDDLEWARE = ["lognitor.integrations.django.LognitorMiddleware", ...]
LOGNITOR = {"api_key": "lgn_...", "service": "django-app"}
Flask
from lognitor.integrations.flask import init_app
init_app(app, api_key="lgn_...", service="flask-app")
FastAPI
from lognitor.integrations.fastapi import LognitorMiddleware
app.add_middleware(LognitorMiddleware, api_key="lgn_...", service="fastapi-app")
Advanced
Timer Decorator
@lognitor.timed("process_payment")
def process_payment(order):
...
Heartbeat Decorator
@lognitor.heartbeat("cron-token")
def nightly_cleanup():
...
Child Loggers
payment_logger = lognitor.child(service="payments", tags=["billing"])
payment_logger.error("Card declined")
Test Transport
from lognitor import LognitorClient, LognitorConfig, MemoryTransport
transport = MemoryTransport()
config = LognitorConfig(api_key="test", transport=transport)
client = LognitorClient(config)
client.info("Hello")
client.flush()
assert len(transport.logs) == 1
Compatibility
Python 3.8+. Zero dependencies.
Development
Prerequisites
- Python 3.8+
- pip
Setup (Editable Install)
cd python
pip install -e .
This installs the SDK in editable mode — any changes to the source code take effect immediately without reinstalling.
Smoke Test
import lognitor
lognitor.init(api_key="test_key", debug=True)
lognitor.info("smoke test", metadata={"env": "dev"})
lognitor.flush()
Or from the command line:
python -c "
import lognitor
lognitor.init(api_key='test_key', debug=True)
lognitor.info('hello from dev')
lognitor.flush()
"
Run Tests
python -m pytest tests/
# or
python -m unittest discover tests/
Project Structure
lognitor/
├── __init__.py # Public API + singleton
├── client.py # Core client class
├── types.py # Config, LogLevel, UserContext
├── transport.py # HTTP + memory transports
├── batch.py # Thread-safe batch buffer
├── breadcrumbs.py # Ring buffer for breadcrumbs
├── enrichment.py # Hostname, SDK metadata
├── context.py # contextvars request context
├── fingerprint.py # Error fingerprinting
├── truncate.py # Smart payload truncation
├── redact.py # PII redaction
├── utils.py # UUID, JSON, URL scrubbing
├── logging_handler.py # stdlib logging.Handler bridge
├── py.typed # PEP 561 marker
└── integrations/
├── django.py # Django middleware
├── flask.py # Flask init_app
└── fastapi.py # FastAPI/Starlette ASGI middleware
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lognitor-1.0.1.tar.gz.
File metadata
- Download URL: lognitor-1.0.1.tar.gz
- Upload date:
- Size: 21.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5cfa9827cc9de2c940852d0d9b16ae75eedeb85da847fa8faae7a85292e47d0
|
|
| MD5 |
ff289d18e791f3043b4ab16d28727316
|
|
| BLAKE2b-256 |
585a4feecdc68cb023bb7c12e618f3c46454015ae0835b4a159c8f30eb77216a
|
File details
Details for the file lognitor-1.0.1-py3-none-any.whl.
File metadata
- Download URL: lognitor-1.0.1-py3-none-any.whl
- Upload date:
- Size: 27.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0786cc86701b49bfcc8f88c2111c9d3e00b7b2341c3b6c81105b38e5fa442184
|
|
| MD5 |
f16efb0b327e1f810a99f7235b11ae23
|
|
| BLAKE2b-256 |
8401caa37f5f577b5189ebd53efc1a92e288f73486df557b104d76f5b6b1e4fc
|