Server: Skip logging for file downloads

- Don't log every /pack/*/file/* request to reduce overhead
- Helps with large file downloads
This commit is contained in:
SashegDev
2026-05-07 17:53:08 +00:00
parent 1199ca9e21
commit d39b40053a
+8 -1
View File
@@ -157,15 +157,22 @@ class LoggingMiddleware(BaseHTTPMiddleware):
# Return 404 without logging - confuse the bots
return Response(status_code=404, content="")
# Log legitimate requests
# Skip logging for large file downloads (don't spam logs)
is_file_download = path.startswith("/pack/") and "/file/" in path
# Log legitimate requests (except file downloads)
start_time = time.time()
if not is_file_download:
logger.info(f"{request.method} {path} (IP: {client_ip}, ID: {request_id})")
try:
response = await call_next(request)
duration = (time.time() - start_time) * 1000
if not is_file_download:
logger.info(f"{request.method} {path}{response.status_code} ({duration:.0f}ms) [ID: {request_id}]")
response.headers["X-Request-ID"] = request_id
return response