Skip to content

Repository files navigation

request-logging

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).

Install

Not published to PyPI yet — install directly from git:

uv add "request-logging @ git+https://github.com/tgenin/request-logging.git"

Usage

from fastapi import FastAPI
from request_logging import RequestLoggingMiddleware, configure_logging

configure_logging()

app = FastAPI()
app.add_middleware(RequestLoggingMiddleware)

Development

uv sync
make test

About

Personal library for request logging configuration

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages