Auto-log every FastAPI request with timing — one line setup
Project description
reqlog
Auto-log every FastAPI request with timing — one line setup.
Installation
pip install reqlog
Quick Start
from fastapi import FastAPI
from reqlog import setup_request_logging
app = FastAPI()
setup_request_logging(app)
That's it. Every request now gets logged with method, path, status code, response time, and client IP:
2025-01-15 10:23:45 - reqlog - INFO - GET /api/users 200 12.34ms - 192.168.1.1
2025-01-15 10:23:46 - reqlog - WARNING - POST /api/login 401 8.21ms - 192.168.1.1
2025-01-15 10:23:47 - reqlog - ERROR - GET /api/crash 500 3.05ms - 192.168.1.1
Features
- One line setup — just call
setup_request_logging(app) - Timing — response time in milliseconds, also added as
X-Response-Timeheader - Smart log levels — INFO for 2xx/3xx, WARNING for 4xx, ERROR for 5xx
- Skip paths — exclude health checks, metrics, etc.
- Optional header/body logging — enable when you need to debug
- Zero config needed — sensible defaults out of the box
Configuration
Skip Paths
setup_request_logging(app, skip_paths={"/health", "/metrics", "/readiness"})
Log Headers and Body
setup_request_logging(app, log_headers=True, log_body=True)
Custom Log Level
import logging
setup_request_logging(app, level=logging.DEBUG)
Manual Middleware Setup
If you prefer more control, add the middleware directly:
from reqlog import RequestLogMiddleware
app.add_middleware(
RequestLogMiddleware,
skip_paths={"/health"},
log_headers=True,
log_body=False,
)
Response Time Header
Every response includes an X-Response-Time header with the processing time:
X-Response-Time: 12.34ms
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file reqlog_middleware-0.1.0.tar.gz.
File metadata
- Download URL: reqlog_middleware-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8475a7dd7c426646ddf9f6c2eb8012f4b764996742dffb664a08e1806cf5bba
|
|
| MD5 |
0dd485ada10078ecfad40f8319d87127
|
|
| BLAKE2b-256 |
4cabbe7fccb6d892fe13ff0fecfcbbe192382c2d197763f32e97b09a255a7668
|
File details
Details for the file reqlog_middleware-0.1.0-py3-none-any.whl.
File metadata
- Download URL: reqlog_middleware-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61b4c379b9742fb6dfe99e11620c4c0c9ec69b7c479c37d2565fea8f7ff2ff84
|
|
| MD5 |
bca6e22f4b62b32bbc5620cc057813a5
|
|
| BLAKE2b-256 |
3a10ddcb4936a57b129aad60003aa9c586b613e97054d4df1a0bf5361450d194
|