Skip to content

austxio/x-endpoint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Request Logger API

A simple FastAPI application that logs all incoming requests to a file.

Features

  • Logs all HTTP requests to separate files per IP address
  • Middleware-based request logging with processing time
  • Catch-all endpoint that accepts any HTTP method and path
  • Health check endpoint
  • Detailed request logging including headers, body, and client IP
  • IP-based log file separation for better organization

Installation

  1. Install dependencies:
python -m venv .venv

pip install -r requirements.txt

Running the Application

python main.py

Or using uvicorn directly:

uvicorn main:app --host 0.0.0.0 --port 8000 --reload

The API will be available at http://localhost:8000

Endpoints

  • GET / - Root endpoint
  • GET /health - Health check
  • ANY /{path:path} - Catch-all endpoint that logs any request

Log Files

Requests are logged to separate files based on the client IP address in the logs/ directory:

  • logs/requests_127_0_0_1.log - Requests from localhost
  • logs/requests_192_168_1_100.log - Requests from 192.168.1.100
  • logs/requests_2001_db8__1.log - Requests from IPv6 address 2001:db8::1

Each log file includes:

  • Timestamp
  • HTTP method and URL
  • Client IP address
  • Request headers
  • Query parameters
  • Request body (for POST/PUT/PATCH requests)
  • Response status code
  • Processing time

Example Usage

# Test the API
curl http://localhost:8000/
curl -X POST http://localhost:8000/test -d '{"key": "value"}'
curl http://localhost:8000/any/path/here

Check the logs/ directory to see IP-specific log files with all logged requests.

About

A simple FastAPI application that logs all incoming requests to a file.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors