Portable structlog request-logging middleware for ASGI apps (FastAPI/Starlette).
Logs one structured event when a request starts and one when it finishes, including
status code, duration, and the client IP (resolved from X-Forwarded-For / X-Real-IP
when behind a reverse proxy). Renders pretty console output in a TTY (local dev) and
JSON lines otherwise (containers, log aggregation).
Not published to PyPI yet — install directly from git:
uv add "request-logging @ git+https://github.com/tgenin/request-logging.git"from fastapi import FastAPI
from request_logging import RequestLoggingMiddleware, configure_logging
configure_logging()
app = FastAPI()
app.add_middleware(RequestLoggingMiddleware)uv sync
make test