From d21bb89eebc9fadfa10ce290d836e586197a9e22 Mon Sep 17 00:00:00 2001
From: hit-cxf <2024111082@stu.hit.edu.cn>
Date: Fri, 15 May 2026 10:46:28 +0800
Subject: [PATCH] 可选关闭后端的http日志输出,防止轮询刷屏

---
 video-claw/video-claw/backend/api_server.py                |    2 +-
 video-claw/video-claw/backend/api/routers/configuration.py |    5 ++++-
 video-claw/video-claw/backend/config.py                    |    4 ++++
 video-claw/video-claw/backend/api/logging_config.py        |    6 ++++++
 video-claw/video-claw/backend/config.yaml.example          |    1 +
 video-claw/video-claw/frontend/app/settings/page.tsx       |    1 +
 6 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/video-claw/video-claw/backend/api/logging_config.py b/video-claw/video-claw/backend/api/logging_config.py
index 2a1b4f9..39783c4 100644
--- a/video-claw/video-claw/backend/api/logging_config.py
+++ b/video-claw/video-claw/backend/api/logging_config.py
@@ -7,6 +7,11 @@
 _listener = None
 
 
+def apply_access_log_setting():
+    """Apply the runtime access-log switch for uvicorn request logs."""
+    logging.getLogger("uvicorn.access").disabled = not Config.ACCESS_LOG
+
+
 class AIGCFormatter(logging.Formatter):
     """Custom log formatter that adds level icons for better readability."""
 
@@ -54,6 +59,7 @@
         logger.handlers.clear()
         logger.propagate = True
         logger.setLevel(logging.WARNING if name == "httpx" else level)
+    apply_access_log_setting()
 
     _listener = listener
     return listener
diff --git a/video-claw/video-claw/backend/api/routers/configuration.py b/video-claw/video-claw/backend/api/routers/configuration.py
index b8a5a85..9fdd11f 100644
--- a/video-claw/video-claw/backend/api/routers/configuration.py
+++ b/video-claw/video-claw/backend/api/routers/configuration.py
@@ -3,6 +3,7 @@
 from fastapi import APIRouter
 from pydantic import BaseModel, Field
 
+from api.logging_config import apply_access_log_setting
 from config import Config, CONFIG_PATH
 
 router = APIRouter(tags=["Configuration"])
@@ -22,7 +23,9 @@
 
 @router.put("/api/config")
 async def update_config(req: ConfigUpdateRequest):
+    config = Config.update_config(req.values)
+    apply_access_log_setting()
     return {
-        "config": Config.update_config(req.values),
+        "config": config,
         "path": str(CONFIG_PATH),
     }
diff --git a/video-claw/video-claw/backend/api_server.py b/video-claw/video-claw/backend/api_server.py
index f564fd0..70854ba 100644
--- a/video-claw/video-claw/backend/api_server.py
+++ b/video-claw/video-claw/backend/api_server.py
@@ -17,7 +17,7 @@
 
 
 def main():
-    uvicorn.run(app, host=settings.HOST, port=settings.PORT)
+    uvicorn.run(app, host=settings.HOST, port=settings.PORT, access_log=settings.ACCESS_LOG)
 
 
 if __name__ == "__main__":
diff --git a/video-claw/video-claw/backend/config.py b/video-claw/video-claw/backend/config.py
index baac278..62fbdea 100644
--- a/video-claw/video-claw/backend/config.py
+++ b/video-claw/video-claw/backend/config.py
@@ -18,6 +18,7 @@
         "host": "127.0.0.1",
         "port": 8000,
         "debug": False,
+        "access_log": False,
     },
     "api_providers": {
         "common": {
@@ -98,6 +99,7 @@
     except (TypeError, ValueError):
         server["port"] = DEFAULT_CONFIG["server"]["port"]
     server["debug"] = _as_bool(server.get("debug"))
+    server["access_log"] = _as_bool(server.get("access_log"))
     server.pop("admin_password", None)
 
     common = clean["api_providers"]["common"]
@@ -166,6 +168,7 @@
     HOST = _get(CONFIG, "server.host")
     PORT = _get(CONFIG, "server.port")
     DEBUG = _get(CONFIG, "server.debug")
+    ACCESS_LOG = _get(CONFIG, "server.access_log")
 
     PRINT_MODEL_INPUT = _get(CONFIG, "api_providers.common.print_model_input")
     PROXY = _get(CONFIG, "api_providers.common.proxy")
@@ -234,6 +237,7 @@
         cls.HOST = _get(clean, "server.host")
         cls.PORT = _get(clean, "server.port")
         cls.DEBUG = _get(clean, "server.debug")
+        cls.ACCESS_LOG = _get(clean, "server.access_log")
 
         cls.PRINT_MODEL_INPUT = _get(clean, "api_providers.common.print_model_input")
         cls.PROXY = _get(clean, "api_providers.common.proxy")
diff --git a/video-claw/video-claw/backend/config.yaml.example b/video-claw/video-claw/backend/config.yaml.example
index 85993cd..3d73f7c 100644
--- a/video-claw/video-claw/backend/config.yaml.example
+++ b/video-claw/video-claw/backend/config.yaml.example
@@ -3,6 +3,7 @@
   host: 127.0.0.1
   port: 8000
   debug: false
+  access_log: false
 api_providers:
   common:
     print_model_input: false
diff --git a/video-claw/video-claw/frontend/app/settings/page.tsx b/video-claw/video-claw/frontend/app/settings/page.tsx
index d2d1ccb..20f4933 100644
--- a/video-claw/video-claw/frontend/app/settings/page.tsx
+++ b/video-claw/video-claw/frontend/app/settings/page.tsx
@@ -39,6 +39,7 @@
       { path: 'server.host', label: 'host' },
       { path: 'server.port', label: 'port', type: 'number' },
       { path: 'server.debug', label: 'debug', type: 'boolean' },
+      { path: 'server.access_log', label: 'access_log', type: 'boolean' },
     ],
   },
   {

--
Gitblit v1.8.0