Skip to content

Structured Logging

JustAPI uses tracing for structured logging, supporting both human-readable text and machine-parseable JSON formats.

By default, JustAPI logs to stdout in a human-readable format:

Terminal window
RUST_LOG=info python app.py

Enable JSON logging for production log aggregation:

from justapi.logging import init_json_logging
init_json_logging()

JSON output:

{"timestamp":"2026-07-24T15:00:00Z","level":"INFO","message":"Server started","addr":"127.0.0.1:8000"}
{"timestamp":"2026-07-24T15:00:01Z","level":"INFO","message":"Request completed","method":"GET","path":"/items/42","status":200,"duration_ms":1.2}

Set via RUST_LOG environment variable:

Level Description
error Only errors
warn Warnings and errors
info Normal operational messages (default)
debug Detailed debugging
trace Very detailed, high-frequency events
Terminal window
RUST_LOG=warn python app.py # Less verbose
RUST_LOG=debug python app.py # More verbose
  • Set RUST_LOG=info in production
  • Do not log request bodies (may contain PII/secrets)
  • Use JSON format for log aggregation (ELK, Loki, Datadog, etc.)
  • Configure log sampling for high-traffic endpoints