Files
Wu Clan 079b994541 Update the pytz library to zoneinfo (#226)
* Update the pytz library to zoneinfo

* delete debug print
2023-10-16 18:45:08 +08:00

19 lines
695 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from fastapi import Request, Response
from starlette.middleware.base import BaseHTTPMiddleware, RequestResponseEndpoint
from backend.app.common.log import log
from backend.app.utils.timezone import timezone
class AccessMiddleware(BaseHTTPMiddleware):
"""记录请求日志中间件"""
async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -> Response:
start_time = timezone.now()
response = await call_next(request)
end_time = timezone.now()
log.info(f'{response.status_code} {request.client.host} {request.method} {request.url} {end_time - start_time}')
return response