From bc6f64e546b83ab156d692793600aa5e143681e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Sat, 26 Jul 2025 22:50:50 +0200 Subject: [PATCH] logi --- app.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index ceb8a27..f2d8a83 100644 --- a/app.py +++ b/app.py @@ -637,16 +637,17 @@ def start_timer(): def log_request(response): if request.path == "/healthcheck": return response - client_ip = get_client_ip() + + ip = get_client_ip() method = request.method path = request.path status = response.status_code length = response.content_length or "-" - duration = round((time.time() - request._start_time) * 1000, 2) - user_agent = request.headers.get("User-Agent", "-") - log_msg = ( - f"{client_ip} - \"{method} {path}\" {status} {length} {duration}ms \"{user_agent}\"" - ) + start = getattr(request, "_start_time", None) + duration = round((time.time() - start) * 1000, 2) if start else "-" + agent = request.headers.get("User-Agent", "-") + + log_msg = f"{ip} - \"{method} {path}\" {status} {length} {duration}ms \"{agent}\"" app.logger.info(log_msg) return response