diff --git a/backend/Dockerfile b/backend/Dockerfile index a448caa..cace536 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -10,4 +10,4 @@ RUN pip install --no-cache-dir -U -r backend/requirements.txt ENV PYTHONPATH=/app EXPOSE 8080 -ENTRYPOINT ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "8080", "--workers", "4"] \ No newline at end of file +ENTRYPOINT ["uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "8080", "--workers", "4", "--no-access-log"] \ No newline at end of file diff --git a/backend/main.py b/backend/main.py index 6376a1e..e15295b 100644 --- a/backend/main.py +++ b/backend/main.py @@ -57,4 +57,4 @@ async def lifespan(app: FastAPI): if __name__ == "__main__": import uvicorn - uvicorn.run(app, host="0.0.0.0", port=8080) + uvicorn.run(app, host="0.0.0.0", port=8080, access_log=False) diff --git a/backend/middleware/logging.py b/backend/middleware/logging.py index 78596a3..b68b8f1 100644 --- a/backend/middleware/logging.py +++ b/backend/middleware/logging.py @@ -1,3 +1,4 @@ +import json import logging import time from fastapi import Request @@ -9,6 +10,14 @@ class AccessLogMiddleware(BaseHTTPMiddleware): async def dispatch(self, request: Request, call_next): start = time.time() + model = "-" + if request.method in ("POST", "PUT", "PATCH"): + try: + body = await request.body() + data = json.loads(body) + model = data.get("model", "-") + except Exception: + pass response = await call_next(request) duration_ms = (time.time() - start) * 1000 token = request.headers.get("authorization", "") @@ -17,10 +26,11 @@ async def dispatch(self, request: Request, call_next): else: token = "-" access_logger.info( - "%s %s %s %d %.0fms", + "%s %s %s model=%s %d %.0fms", token, request.method, request.url.path, + model, response.status_code, duration_ms, ) diff --git a/backend/redis_cache.py b/backend/redis_cache.py index e8e7adf..053c1a9 100644 --- a/backend/redis_cache.py +++ b/backend/redis_cache.py @@ -38,7 +38,7 @@ def __init__( ) # Test connection self.redis_client.ping() - logger.info(f"Connected to Redis at {self.host}:{self.port}") + logger.debug(f"Connected to Redis at {self.host}:{self.port}") except Exception as e: logger.error(f"Failed to connect to Redis: {e}") # Fallback to in-memory set for development/testing