Structured Logging
JustAPI uses tracing for structured logging, supporting both human-readable text and machine-parseable JSON formats.
Default Logging
Section titled “Default Logging”By default, JustAPI logs to stdout in a human-readable format:
RUST_LOG=info python app.pyJSON Log Format
Section titled “JSON Log Format”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}Log Levels
Section titled “Log Levels”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 |
RUST_LOG=warn python app.py # Less verboseRUST_LOG=debug python app.py # More verboseProduction Guidelines
Section titled “Production Guidelines”- Set
RUST_LOG=infoin 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
See Also
Section titled “See Also”- Metrics & Monitoring — Prometheus metrics
- OpenTelemetry — Distributed tracing
- Health Checks — Health endpoints