加入debug日志查看功能

This commit is contained in:
liuwei
2025-05-08 11:14:25 +08:00
parent cedd5722b3
commit 66db51c328

View File

@@ -43,7 +43,6 @@
logType: 'info', logType: 'info',
logLines: 100, logLines: 100,
logContent: [], logContent: [],
logContentHtml: '', // 新增
currentView: '9' // 设置当前菜单项 currentView: '9' // 设置当前菜单项
} }
}, },
@@ -57,39 +56,17 @@
.then(response => { .then(response => {
if (response.data.success) { if (response.data.success) {
this.logContent = response.data.data.content || []; this.logContent = response.data.data.content || [];
// 处理为带颜色的HTML
this.logContentHtml = this.logContent.map(line => {
if (line.includes('ERROR')) {
return `<span style="color: red;">${this.escapeHtml(line)}</span>`;
} else if (line.includes('WARNING') || line.includes('WARN')) {
return `<span style="color: orange;">${this.escapeHtml(line)}</span>`;
} else if (line.includes('DEBUG')) {
return `<span style="color: #409EFF;">${this.escapeHtml(line)}</span>`;
} else if (line.includes('INFO')) {
return `<span style="color: green;">${this.escapeHtml(line)}</span>`;
} else {
return `<span>${this.escapeHtml(line)}</span>`;
}
}).join('');
} else { } else {
this.$message.error('加载日志失败'); this.$message.error('加载日志失败');
this.logContentHtml = '';
} }
}) })
.catch(error => { .catch(error => {
console.error('加载日志出错:', error); console.error('加载日志出错:', error);
this.$message.error('加载日志出错'); this.$message.error('加载日志出错');
this.logContentHtml = '';
}) })
.finally(() => { .finally(() => {
this.loading = false; this.loading = false;
}); });
},
escapeHtml(text) {
// 防止XSS
return text.replace(/[<>&"]/g, function(c) {
return {'<':'&lt;','>':'&gt;','&':'&amp;','"':'&quot;'}[c];
});
} }
} }
}); });