Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

raven_logger-1.0.2.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

raven_logger-1.0.2-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: raven_logger-1.0.2.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for raven_logger-1.0.2.tar.gz
Algorithm Hash digest
SHA256 b3387a0c67f808327759ac72b1feea90c2caeccdea3ba52472b684da0e115971
MD5 aeabcd9ce055b6edc2ba21e46f965ca5
BLAKE2b-256 fd60f33cefb2215118124d4d47df14f617aa53caff9b875ce291a841b5e2d954

See more details on using hashes here.

File details

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

File metadata

  • Download URL: raven_logger-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for raven_logger-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3d9f44bbf0df5241192667e532b600fc94bbafdbab099344b0883095997bb1f1
MD5 896de6b2f71c3cf6ab76b1c8c168001d
BLAKE2b-256 b4ea2c2c939b463abd41efedbf23c98316d0da92d41ff85b311f05ea87c282ca

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