from time import time
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.requests import Request
from starlette.responses import Response
from loguru import logger

class ActivityTrackerMiddleware(BaseHTTPMiddleware):
    async def dispatch(self, request: Request, call_next):
        start_time = time()
        response: Response = await call_next(request)
        process_time = time() - start_time
        logger.info(f"Request processed in {process_time:.4f} seconds")
        return response