rag-chatbot / app /api /middleware /logging.py
Abeshith's picture
RAG Chatbot with LangChain, FastAPI, and service layer architecture
64d7fdf
raw
history blame contribute delete
503 Bytes
from fastapi import Request
from app.utils.logger import logger
import time
async def logging_middleware(request: Request, call_next):
start_time = time.time()
logger.info(f"Request: {request.method} {request.url.path}")
response = await call_next(request)
process_time = time.time() - start_time
logger.info(
f"Response: {request.method} {request.url.path} "
f"Status: {response.status_code} Time: {process_time:.2f}s"
)
return response