diff --git a/clipwright/api/app.py b/clipwright/api/app.py index 2fb0b7e..b3dc953 100644 --- a/clipwright/api/app.py +++ b/clipwright/api/app.py @@ -1,3 +1,4 @@ +import logging import os from clipwright.pipeline import llm_backend, profiles import re @@ -1470,6 +1471,25 @@ async def lifespan(app: FastAPI): yield # Cleanup (optional: cancel worker) +# Health probes (Docker, every 5 s) and the dashboard's 2 s job-status poll would +# otherwise fill uvicorn's access log with thousands of identical lines and bury +# the real job output. Drop those from the access logger only: the requests are +# still served normally, just not echoed to the console. +_QUIET_ACCESS_PREFIXES = ("/health", "/api/status/") + + +class _QuietAccessPaths(logging.Filter): + """Suppress access-log lines for health checks and job-status polling.""" + + def filter(self, record: logging.LogRecord) -> bool: + args = record.args + path = args[2] if isinstance(args, tuple) and len(args) >= 3 else "" + return not str(path).startswith(_QUIET_ACCESS_PREFIXES) + + +logging.getLogger("uvicorn.access").addFilter(_QuietAccessPaths()) + + app = FastAPI(lifespan=lifespan) # Free public tools behind the /tools SEO pages: YouTube transcript (existing diff --git a/tests/test_access_log_filter.py b/tests/test_access_log_filter.py new file mode 100644 index 0000000..1bfbead --- /dev/null +++ b/tests/test_access_log_filter.py @@ -0,0 +1,34 @@ +"""The access-log filter that hides health checks and job-status polling.""" + +import logging + +from clipwright.api.app import _QuietAccessPaths + + +def _record(path): + return logging.LogRecord( + "uvicorn.access", logging.INFO, __file__, 1, "msg", + ("1.2.3.4", "GET", path, "HTTP/1.1", 200), None, + ) + + +def test_drops_health_and_status_lines(): + f = _QuietAccessPaths() + assert f.filter(_record("/health")) is False + assert f.filter(_record("/health/ready")) is False + assert f.filter(_record("/api/status/4c533b81-ef05-4b51-80a3-137046577888")) is False + + +def test_keeps_real_requests(): + f = _QuietAccessPaths() + assert f.filter(_record("/api/config")) is True + assert f.filter(_record("/api/uploads/abc")) is True + assert f.filter(_record("/videos/job/clip.mp4")) is True + + +def test_survives_unexpected_record_args(): + # uvicorn access records always carry the args tuple, but a filter must never + # raise on a differently-shaped record. + f = _QuietAccessPaths() + rec = logging.LogRecord("uvicorn.access", logging.INFO, __file__, 1, "msg", None, None) + assert f.filter(rec) is True