添加运行日志

This commit is contained in:
liuwei
2025-04-02 11:17:22 +08:00
parent cf9b2ee3d3
commit d4813fc0cf
3 changed files with 147 additions and 1 deletions

View File

@@ -169,6 +169,11 @@ class DashboardServer:
"""消息列表页面"""
return render_template('message_list.html')
# 在路由部分添加
@app.route('/wx_logs')
@login_required
def wx_logs():
return render_template('wx_logs.html')
# 在_create_app方法中添加新的路由
@app.route('/robot_management')
@login_required
@@ -567,6 +572,41 @@ class DashboardServer:
except Exception as e:
self.logger.error(f"获取群组列表失败: {e}")
return jsonify({'error': str(e)}), 500
@app.route('/api_wx_logs')
@login_required
def api_wx_logs():
try:
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__))))
if log_type == 'error':
log_file = os.path.join(base_dir, 'wx_error.log')
else:
log_file = os.path.join(base_dir, 'wx_info.log')
# 读取日志文件
log_content = []
if os.path.exists(log_file):
with open(log_file, 'r', encoding='utf-8', errors='ignore') as f:
# 使用deque获取最后N行
log_content = list(deque(f, lines))
return jsonify({
"success": True,
"data": {
"log_type": log_type,
"log_file": log_file,
"content": log_content,
"lines": len(log_content)
}
})
except Exception as e:
self.logger.error(f"获取微信日志失败: {e}")
return jsonify({"success": False, "error": str(e)}), 500
return app