Skip to main content

reqlog

PyPI version License: MIT Python 3.9+

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-Time header
  • 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

Release files for reqlog-middleware 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for reqlog-middleware 0.1.0
File Size Uploaded
reqlog_middleware-0.1.0.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for reqlog-middleware 0.1.0
File Interpreter ABI Platform
reqlog_middleware-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.3 kB

Release files / reqlog_middleware-0.1.0.tar.gz

Download URL reqlog_middleware-0.1.0.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e8475a7dd7c426646ddf9f6c2eb8012f4b764996742dffb664a08e1806cf5bba
BLAKE2b-256 checksum
How to use checksums
4cabbe7fccb6d892fe13ff0fecfcbbe192382c2d197763f32e97b09a255a7668
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / reqlog_middleware-0.1.0-py3-none-any.whl

Download URL reqlog_middleware-0.1.0-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
61b4c379b9742fb6dfe99e11620c4c0c9ec69b7c479c37d2565fea8f7ff2ff84
BLAKE2b-256 checksum
How to use checksums
3a10ddcb4936a57b129aad60003aa9c586b613e97054d4df1a0bf5361450d194
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page