Cookbook
Practical solutions to common logging problems. Each recipe is self-contained with copy-pasteable code.
Cookbook
- FastAPI Microservices in Production
- FastAPI JSON logging to stdout (Uvicorn access logs included)
- FastAPI request_id logging (correlation ID middleware, concurrency-safe)
- Django Structured JSON Logging with Correlation IDs
- Non-blocking logging in FastAPI (protect latency under slow sinks)
- One FastAPI logging config for dev + prod (Uvicorn/Gunicorn)
- Redacting secrets and PII in FastAPI logs (Authorization, tokens, fields)
- Compliance Redaction: What Works and What Doesn’t
- Logging request/response bodies without hanging (safe patterns)
- Skipping health/metrics endpoints (noise reduction)
- Log sampling and rate limiting for FastAPI
- Adaptive Sampling for High-Volume Services
- Graceful shutdown & flushing logs (don’t lose logs on deploy)
- Exception logging in FastAPI with request_id + structured context
- Custom log levels in Python (TRACE, VERBOSE, NOTICE)
Getting Started with Fapilog
New to fapilog? Start here:
Why Fapilog? - Is fapilog right for your project?
Quickstart - Install and run in 2 minutes
Core Concepts - How the async pipeline works
Comparisons - fapilog vs structlog, loguru, stdlib