From c6c6527029ab86e58d1c327298e5bd39fabe40dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=98=E7=94=B3=E7=A5=BA?= <1418875140@qq.com> Date: Thu, 14 May 2026 13:04:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(system):=20=E5=BC=BA=E5=88=B6=E4=BB=A5=20UT?= =?UTF-8?q?F-8=20=E7=BC=96=E7=A0=81=E8=AF=BB=E5=8F=96=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=96=87=E4=BB=B6=EF=BC=8C=E5=BF=BD=E7=95=A5?= =?UTF-8?q?=E7=BC=96=E7=A0=81=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/server/routers/system_router.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/server/routers/system_router.py b/backend/server/routers/system_router.py index 9318e8ae..5cb03a1a 100644 --- a/backend/server/routers/system_router.py +++ b/backend/server/routers/system_router.py @@ -65,7 +65,8 @@ async def get_system_logs(levels: str | None = None, current_user: User = Depend if levels: level_filter = set(level.strip().upper() for level in levels.split(",") if level.strip()) - async with aiofiles.open(LOG_FILE) as f: + # 修复 GBK 编码报错:强制 utf-8 读取,忽略错误 + async with aiofiles.open(LOG_FILE, mode='r', encoding='utf-8', errors='ignore') as f: # 读取最后1000行 lines = [] async for line in f: @@ -91,7 +92,6 @@ async def get_system_logs(levels: str | None = None, current_user: User = Depend logger.error(f"获取系统日志失败: {e}") raise HTTPException(status_code=500, detail=f"获取系统日志失败: {str(e)}") - # ============================================================================= # === 信息管理分组 === # =============================================================================