管理后台 server 使用蓝图模式,降低维护成本,降低修改功能时对其他模块的影响
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user