Metadata-Version: 2.4
Name: reqlog-middleware
Version: 0.1.0
Summary: Auto-log every FastAPI request with timing — one line setup
Author-email: Shahab Rashidian Dezfuly <mm4heidary@gmail.com>
License: MIT
Project-URL: Homepage, https://github.com/shahabRDZ/reqlog
Project-URL: Repository, https://github.com/shahabRDZ/reqlog
Project-URL: Issues, https://github.com/shahabRDZ/reqlog/issues
Keywords: fastapi,logging,middleware,request-logging,http,monitoring
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: FastAPI
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: System :: Logging
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastapi>=0.68.0
Requires-Dist: starlette>=0.14.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: httpx>=0.23.0; extra == "dev"
Dynamic: license-file

# reqlog

[![PyPI version](https://badge.fury.io/py/reqlog.svg)](https://pypi.org/project/reqlog/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)

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

## Installation

```bash
pip install reqlog
```

## Quick Start

```python
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

```python
setup_request_logging(app, skip_paths={"/health", "/metrics", "/readiness"})
```

### Log Headers and Body

```python
setup_request_logging(app, log_headers=True, log_body=True)
```

### Custom Log Level

```python
import logging
setup_request_logging(app, level=logging.DEBUG)
```

### Manual Middleware Setup

If you prefer more control, add the middleware directly:

```python
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
