From 0f8d56066fa06a28e0199212488cd5aac718e3e0 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Sun, 25 Oct 2026 07:13:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=85=8D=E7=BD=AE=20nqi=20=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E5=B9=B6=E5=85=B3=E9=97=AD=E6=89=93=E5=8C=85=E7=89=88?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/main.py | 16 ++++++++++++++++ backend/nqi_backend.py | 5 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/backend/app/main.py b/backend/app/main.py index 24a91b3..b8f06ff 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -1,6 +1,8 @@ """本机接口。只监听 127.0.0.1。功能路由按目录挂上。""" import asyncio +import logging +import sys from contextlib import asynccontextmanager, suppress from fastapi import FastAPI @@ -20,8 +22,21 @@ ORIGINS = [ ] +def configure_logging() -> None: + """让 nqi.* 的 INFO 写到标准输出。uvicorn 默认不接管这个记录器。""" + nqi = logging.getLogger("nqi") + nqi.setLevel(logging.INFO) + if not any(getattr(handler, "_nqi_stdout", False) for handler in nqi.handlers): + handler = logging.StreamHandler(sys.stdout) + handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(name)s: %(message)s")) + handler._nqi_stdout = True + nqi.addHandler(handler) + nqi.propagate = False + + @asynccontextmanager async def lifespan(_app: FastAPI): + configure_logging() keepalive = asyncio.create_task(session_keepalive()) try: yield @@ -58,6 +73,7 @@ if __name__ == "__main__": import uvicorn + configure_logging() chosen = os.environ.get("NQI_PORT") if chosen: port = int(chosen) diff --git a/backend/nqi_backend.py b/backend/nqi_backend.py index b747f17..f8d08d6 100644 --- a/backend/nqi_backend.py +++ b/backend/nqi_backend.py @@ -4,12 +4,13 @@ import os import uvicorn -from app.main import app +from app.main import app, configure_logging def main() -> None: + configure_logging() port = int(os.environ["NQI_PORT"]) - uvicorn.run(app, host="127.0.0.1", port=port, log_level="info") + uvicorn.run(app, host="127.0.0.1", port=port, log_level="info", access_log=False) if __name__ == "__main__":