Skip to main content

Auto-log every FastAPI request with timing — one line setup

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reqlog_middleware-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reqlog_middleware-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

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

Hashes for reqlog_middleware-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e8475a7dd7c426646ddf9f6c2eb8012f4b764996742dffb664a08e1806cf5bba
MD5 0dd485ada10078ecfad40f8319d87127
BLAKE2b-256 4cabbe7fccb6d892fe13ff0fecfcbbe192382c2d197763f32e97b09a255a7668

See more details on using hashes here.

File details

Details for the file reqlog_middleware-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for reqlog_middleware-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61b4c379b9742fb6dfe99e11620c4c0c9ec69b7c479c37d2565fea8f7ff2ff84
MD5 bca6e22f4b62b32bbc5620cc057813a5
BLAKE2b-256 3a10ddcb4936a57b129aad60003aa9c586b613e97054d4df1a0bf5361450d194

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page