Metadata-Version: 2.4
Name: lognitor
Version: 1.0.1
Summary: Lognitor SDK for Python — log management, error tracking, and monitoring
Author: Lognitor Inc.
License: Proprietary
Project-URL: Homepage, https://lognitor.com
Project-URL: Documentation, https://docs.lognitor.com/python
Project-URL: Repository, https://github.com/grenzpro/lognitor-python
Project-URL: Issues, https://github.com/grenzpro/lognitor-python/issues
Keywords: logging,error-tracking,monitoring,lognitor,observability
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: System :: Logging
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# lognitor

Official Lognitor SDK for Python — log management, error tracking, and monitoring.

## Install

```bash
pip install lognitor
```

## Quick Start

```python
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

```python
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

```python
try:
    process_order(order)
except Exception as exc:
    event_id = lognitor.capture_exception(exc)
```

Uncaught exceptions captured automatically via `sys.excepthook`.

## stdlib logging Integration

```python
import logging
handler = lognitor.LogHandler(level=logging.WARNING)
logging.getLogger().addHandler(handler)
```

## Framework Integrations

### Django

```python
# settings.py
MIDDLEWARE = ["lognitor.integrations.django.LognitorMiddleware", ...]
LOGNITOR = {"api_key": "lgn_...", "service": "django-app"}
```

### Flask

```python
from lognitor.integrations.flask import init_app
init_app(app, api_key="lgn_...", service="flask-app")
```

### FastAPI

```python
from lognitor.integrations.fastapi import LognitorMiddleware
app.add_middleware(LognitorMiddleware, api_key="lgn_...", service="fastapi-app")
```

## Advanced

### Timer Decorator

```python
@lognitor.timed("process_payment")
def process_payment(order):
    ...
```

### Heartbeat Decorator

```python
@lognitor.heartbeat("cron-token")
def nightly_cleanup():
    ...
```

### Child Loggers

```python
payment_logger = lognitor.child(service="payments", tags=["billing"])
payment_logger.error("Card declined")
```

### Test Transport

```python
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)

```bash
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

```python
import lognitor

lognitor.init(api_key="test_key", debug=True)
lognitor.info("smoke test", metadata={"env": "dev"})
lognitor.flush()
```

Or from the command line:

```bash
python -c "
import lognitor
lognitor.init(api_key='test_key', debug=True)
lognitor.info('hello from dev')
lognitor.flush()
"
```

### Run Tests

```bash
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
```
