Application logging SDK for raven-log contract compliance — structured, validated JSON logs
Project description
raven-logger
Application logging SDK for raven-log contract compliance — emit validated, structured JSON records from any Python service.
Install
pip install raven-logger
Quick start
from raven_logger import raven_log, new_trace_id, new_span_id
trace = new_trace_id()
raven_log(
level="INFO",
criticality="P3",
message="User signed in",
service="auth-service",
env="prod",
principal="user:42",
project="my-app",
trace_id=trace,
)
Output (one JSON line to stdout):
{
"schema_version": "1",
"timestamp": "2026-06-22T12:00:00.000000+00:00",
"level": "INFO",
"criticality": "P3",
"service": "auth-service",
"env": "prod",
"trace_id": "550e8400-e29b-41d4-a716-446655440000",
"span_id": "a1b2c3d4",
"principal": "user:42",
"error_code": "",
"message": "User signed in",
"context": {},
"sample_payload": "",
"project": "my-app"
}
API
raven_log(...) -> dict
| Parameter | Type | Required | Description |
|---|---|---|---|
level |
"ERROR" | "WARN" | "INFO" | "DEBUG" |
✓ | Log level |
criticality |
"P1" | "P2" | "P3" | "P4" |
✓ | Business criticality |
message |
str |
✓ | Human-readable description |
service |
str |
✓ | Emitting service name |
env |
"prod" | "staging" | "dev" |
✓ | Deployment environment |
principal |
str |
✓ | Acting identity (e.g. "user:42") |
project |
str |
✓ | Project/team identifier |
error_code |
str |
Required for ERROR/WARN |
Machine-readable error code |
trace_id |
str |
— | Distributed trace ID (auto-generated if omitted) |
span_id |
str |
— | Span ID (auto-generated if omitted) |
context |
dict |
— | Arbitrary structured context |
sample_payload |
str |
— | Redacted payload snippet |
Returns the emitted record as a dict.
new_trace_id() -> str
Generates a UUID v4 trace ID for use at service boundaries.
new_span_id() -> str
Generates an 8-character span ID for operations within a trace.
Custom emitter (Kafka, etc.)
Pass _emit to replace the default stdout writer:
def kafka_emit(record: dict) -> None:
producer.send("logs", json.dumps(record).encode())
raven_log(..., _emit=kafka_emit)
License
MIT © Giggso
Project details
Release history Release notifications | RSS feed
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 raven_logger-1.0.4.tar.gz.
File metadata
- Download URL: raven_logger-1.0.4.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50ca6e3e3a40b1540700b867147e8cdb1551edcd570bfd9af2fa6b9e6be1745f
|
|
| MD5 |
9d20035d4e49cc27b3cf400329fb3f5d
|
|
| BLAKE2b-256 |
85c960ced0216f246ae3e726646ce0eca33f74f11d4937dceefc138dcb0dc9f0
|
File details
Details for the file raven_logger-1.0.4-py3-none-any.whl.
File metadata
- Download URL: raven_logger-1.0.4-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3806ce9ea74b7dd0b59195c4355acd086e85594e398f6e794d2973f8da8d611e
|
|
| MD5 |
039e1d1493351ff7a33cd20aa47d2b59
|
|
| BLAKE2b-256 |
32cacca2782d4f22a7cb5a0c1336c8609381896c9f34916c21718b887be88150
|