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

# Core (stdout emitter only)
pip install raven-logger

# With Kafka emitter support
pip install "raven-logger[kafka]"

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.0",
  "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"
}

Kafka emitter

KafkaEmitter is a production-ready emitter that sends records directly to a Kafka topic. Pass it as _emit to raven_log.

Local / Docker broker (no authentication)

from raven_logger import raven_log, KafkaEmitter

emitter = KafkaEmitter(
    bootstrap_servers="localhost:9092",
    topic="raven-logs",
    cluster_name="local-dev",   # optional label, not sent to broker
)

raven_log(
    level="INFO",
    criticality="P3",
    message="User signed in",
    service="auth-service",
    env="dev",
    principal="user:42",
    project="my-app",
    _emit=emitter,
)

Authenticated cluster (SASL_SSL)

emitter = KafkaEmitter(
    bootstrap_servers="broker.example.com:9092",
    topic="raven-logs",
    sasl_username="my-user",
    sasl_password="my-secret",
)

When sasl_username and sasl_password are provided the security protocol defaults to SASL_SSL. Omit both for PLAINTEXT (local/Docker). Providing only one raises ValueError at construction time.

KafkaEmitter parameters

Parameter Required Default Description
bootstrap_servers Broker address(es), e.g. "localhost:9092"
topic Target Kafka topic
cluster_name "" Human label stored on the instance; not sent to broker
sasl_username None SASL username; must be paired with sasl_password
sasl_password None SASL password; must be paired with sasl_username
security_protocol auto Overrides the auto-detected protocol (PLAINTEXT / SASL_SSL)
sasl_mechanism "PLAIN" SASL mechanism

KafkaEmitter requires confluent-kafka. Install it with pip install "raven-logger[kafka]".

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
_emit callable Custom emitter; defaults to stdout JSON writer

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.

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.8.tar.gz (5.6 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.8-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: raven_logger-1.0.8.tar.gz
  • Upload date:
  • Size: 5.6 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.8.tar.gz
Algorithm Hash digest
SHA256 5a33df393509b96d03e094e1a22bee51da3fd459babed4e8a6c415f4fb881637
MD5 e399852ebac064b135e3cf9df69fbb65
BLAKE2b-256 37f110d2b20874085f9626590356328d0740bec0756f6c50ee840c5c128abeb9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: raven_logger-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 6.0 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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 6d0bb58ef069fb2d9b908aa935bc093491e13644bf3cc445975d6adca30957f6
MD5 797b0b6bfbfc6bd75cc49c13e06348f1
BLAKE2b-256 feb6a2bf2a5d9567a6b4eec774c2177c48af6cdc3b2745725021664ec5d01105

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