From 098c706d9c44bc085e53dc8056f4c891515defad Mon Sep 17 00:00:00 2001 From: mxnoob Date: Mon, 19 Aug 2024 20:23:12 +0300 Subject: [PATCH] [test] logger middleware --- app/core/middleware.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/app/core/middleware.py b/app/core/middleware.py index e0d6755..a90c244 100644 --- a/app/core/middleware.py +++ b/app/core/middleware.py @@ -52,27 +52,27 @@ def hide_details(json_body: dict) -> None: class LoggerMiddleware(BaseHTTPMiddleware): async def dispatch(self, request: Request, call_next) -> Response: - json_body = await self._get_request_json(request) - start_time = time.time() response = await call_next(request) - response_time = round(time.time() - start_time, 5) - - hide_details(json_body) - - data = json.dumps( - get_request_data(request, json_body), - indent=2, - ensure_ascii=False, - ) - logger.info( - "\"%s %s\" %d %ds\nwith data = %s", - request.method, - request.url.path, - response.status_code, - response_time, - data, - ) + + if logger.isEnabledFor(logging.INFO): + response_time = round(time.time() - start_time, 5) + # json_body = await self._get_request_json(request) + json_body = {} + # hide_details(json_body) + data = json.dumps( + get_request_data(request, json_body), + indent=2, + ensure_ascii=False, + ) + logger.info( + "\"%s %s\" %d %ds\nwith data = %s", + request.method, + request.url.path, + response.status_code, + response_time, + data, + ) return response