Skip to main content

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

lognitor-1.0.0.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

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

lognitor-1.0.0-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

Details for the file lognitor-1.0.0.tar.gz.

File metadata

  • Download URL: lognitor-1.0.0.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

Hashes for lognitor-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ac1d383fc46af0368a0cd8e09b24e776a83667a1726f080d11c52237098b783d
MD5 9d8cb2e0b55cb21fb7831f5afef24d7e
BLAKE2b-256 01c94be1cf9db3020d96b4997b6e5d7080a041e180d636755800d6226c697fe7

See more details on using hashes here.

File details

Details for the file lognitor-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: lognitor-1.0.0-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

Hashes for lognitor-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0834ac4daadfc538c0512d7713c813990f052a61955b80fa1cb21d7482e1443d
MD5 b14be9418bd6d54be3a0e77b2347c4dd
BLAKE2b-256 6b94ed206a72d759a5892b0172c8e688103f1a16b2a598bd54b6aaa689ad4c21

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