From 3367764632b435a147ca86ba411a63f0b15cd890 Mon Sep 17 00:00:00 2001 From: extreme4all <40169115+extreme4all@users.noreply.github.com> Date: Fri, 22 Sep 2023 23:35:49 +0200 Subject: [PATCH] better logging --- src/core/fastapi/middleware/logging.py | 33 +++++++++++--------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/core/fastapi/middleware/logging.py b/src/core/fastapi/middleware/logging.py index 2d21cae2..6a21d419 100644 --- a/src/core/fastapi/middleware/logging.py +++ b/src/core/fastapi/middleware/logging.py @@ -8,25 +8,20 @@ class LoggingMiddleware(BaseHTTPMiddleware): async def dispatch(self, request: Request, call_next): - # Start time start_time = time.time() - - # Process request response = await call_next(request) - - # End time - end_time = time.time() - - # Calculate request processing time - process_time = end_time - start_time - - log_info = { - "Request Method": request.method, - "Request URL": str(request.url), - "Response Status Code": response.status_code, - "Processing Time": f"{process_time:.4f}s", - } - # Log the request - logger.info(log_info) - + process_time = time.time() - start_time + + query_params_list = [ + (key, value if key != "token" else "***") + for key, value in request.query_params.items() + ] + + logger.debug( + { + "url": request.url.path, + "params": query_params_list, + "process_time": f"{process_time:.4f}", + } + ) return response