添加运行日志
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -138,6 +138,11 @@
|
||||
<i class="el-icon-chat-line-square"></i>
|
||||
<span slot="title">消息列表</span>
|
||||
</el-menu-item>
|
||||
<!-- 运行日志 -->
|
||||
<el-menu-item index="9">
|
||||
<i class="el-icon-chat-line-square"></i>
|
||||
<span slot="title">运行日志</span>
|
||||
</el-menu-item>
|
||||
</el-menu>
|
||||
</div>
|
||||
|
||||
@@ -190,7 +195,8 @@
|
||||
'4': '/groups',
|
||||
'5': '/errors',
|
||||
'6': '/robot_management',
|
||||
'7': '/messages'
|
||||
'7': '/messages',
|
||||
'9': '/wx_logs'
|
||||
};
|
||||
|
||||
// 如果当前不在对应页面,则跳转
|
||||
|
||||
100
admin/dashboard/templates/wx_logs.html
Normal file
100
admin/dashboard/templates/wx_logs.html
Normal file
@@ -0,0 +1,100 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}微信日志查看{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div>
|
||||
<h1>微信日志查看</h1>
|
||||
|
||||
<el-card class="log-card">
|
||||
<div slot="header" class="clearfix">
|
||||
<span>日志查看</span>
|
||||
<el-radio-group v-model="logType" size="small" style="margin-left: 20px;" @change="loadLogs">
|
||||
<el-radio-button label="info">信息日志</el-radio-button>
|
||||
<el-radio-button label="error">错误日志</el-radio-button>
|
||||
</el-radio-group>
|
||||
<el-select v-model="logLines" size="small" style="margin-left: 20px;" @change="loadLogs">
|
||||
<el-option label="最近100行" :value="100"></el-option>
|
||||
<el-option label="最近500行" :value="500"></el-option>
|
||||
<el-option label="最近1000行" :value="1000"></el-option>
|
||||
</el-select>
|
||||
<el-button style="float: right; padding: 3px 0" type="text" @click="loadLogs">刷新</el-button>
|
||||
</div>
|
||||
|
||||
<div v-loading="loading">
|
||||
<div v-if="logContent.length > 0" class="log-content">
|
||||
<pre>{{ logContent.join('') }}</pre>
|
||||
</div>
|
||||
<div v-else class="empty-log">
|
||||
<el-empty description="暂无日志内容"></el-empty>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
new Vue({
|
||||
el: '#app',
|
||||
mixins: [baseApp],
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
logType: 'info',
|
||||
logLines: 100,
|
||||
logContent: [],
|
||||
currentView: '9' // 设置当前菜单项
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.loadLogs();
|
||||
},
|
||||
methods: {
|
||||
loadLogs() {
|
||||
this.loading = true;
|
||||
axios.get(`/api/wx_logs?type=${this.logType}&lines=${this.logLines}`)
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
this.logContent = response.data.data.content || [];
|
||||
} else {
|
||||
this.$message.error('加载日志失败');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('加载日志出错:', error);
|
||||
this.$message.error('加载日志出错');
|
||||
})
|
||||
.finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.log-card {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.log-content {
|
||||
max-height: 600px;
|
||||
overflow-y: auto;
|
||||
background-color: #f5f5f5;
|
||||
padding: 10px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.log-content pre {
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.empty-log {
|
||||
padding: 40px 0;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user