diff --git a/admin/dashboard/server.py b/admin/dashboard/server.py index 8c97674..6d582ea 100644 --- a/admin/dashboard/server.py +++ b/admin/dashboard/server.py @@ -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 diff --git a/admin/dashboard/templates/base.html b/admin/dashboard/templates/base.html index 7334854..506a599 100644 --- a/admin/dashboard/templates/base.html +++ b/admin/dashboard/templates/base.html @@ -138,6 +138,11 @@ 消息列表 + + + + 运行日志 + @@ -190,7 +195,8 @@ '4': '/groups', '5': '/errors', '6': '/robot_management', - '7': '/messages' + '7': '/messages', + '9': '/wx_logs' }; // 如果当前不在对应页面,则跳转 diff --git a/admin/dashboard/templates/wx_logs.html b/admin/dashboard/templates/wx_logs.html new file mode 100644 index 0000000..4012456 --- /dev/null +++ b/admin/dashboard/templates/wx_logs.html @@ -0,0 +1,100 @@ +{% extends "base.html" %} + +{% block title %}微信日志查看{% endblock %} + +{% block content %} +
+

微信日志查看

+ + +
+ 日志查看 + + 信息日志 + 错误日志 + + + + + + + 刷新 +
+ +
+
+
{{ logContent.join('') }}
+
+
+ +
+
+
+
+{% endblock %} + +{% block scripts %} + + + +{% endblock %} \ No newline at end of file