From 43a6d39b4c846b4f3f2d500e96b62f19bc5860df Mon Sep 17 00:00:00 2001 From: liuwei Date: Thu, 3 Apr 2025 12:02:45 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=90=8E=E5=8F=B0=20server?= =?UTF-8?q?=20=E4=BD=BF=E7=94=A8=E8=93=9D=E5=9B=BE=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E9=99=8D=E4=BD=8E=E7=BB=B4=E6=8A=A4=E6=88=90=E6=9C=AC?= =?UTF-8?q?=EF=BC=8C=E9=99=8D=E4=BD=8E=E4=BF=AE=E6=94=B9=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=97=B6=E5=AF=B9=E5=85=B6=E4=BB=96=E6=A8=A1=E5=9D=97=E7=9A=84?= =?UTF-8?q?=E5=BD=B1=E5=93=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/dashboard/blueprints/system.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/admin/dashboard/blueprints/system.py b/admin/dashboard/blueprints/system.py index 6185f72..d0700c4 100644 --- a/admin/dashboard/blueprints/system.py +++ b/admin/dashboard/blueprints/system.py @@ -1,4 +1,4 @@ -from flask import Blueprint, render_template, jsonify, request, send_from_directory +from flask import Blueprint, render_template, jsonify, request, send_from_directory, current_app from .auth import login_required import logging import os @@ -47,12 +47,17 @@ def api_wx_logs(): log_type = request.args.get('type', 'info') # 默认显示info日志 lines = request.args.get('lines', 100, type=int) # 默认显示最后100行 - # 确定日志文件路径 - base_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + # 修正日志文件路径计算,获取项目根目录 + # 从当前文件位置向上导航4层到项目根目录 + # blueprints -> dashboard -> admin -> WeChatRobot + project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..')) + if log_type == 'error': - log_file = os.path.join(base_dir, 'wx_error.log') + log_file = os.path.join(project_root, 'wx_error.log') else: - log_file = os.path.join(base_dir, 'wx_info.log') + log_file = os.path.join(project_root, 'wx_info.log') + + logger.info(f"尝试读取日志文件: {log_file}") # 读取日志文件 log_content = [] @@ -60,6 +65,8 @@ def api_wx_logs(): with open(log_file, 'r', encoding='utf-8', errors='ignore') as f: # 使用deque获取最后N行 log_content = list(deque(f, lines)) + else: + logger.warning(f"日志文件不存在: {log_file}") return jsonify({ "success": True,