优化log显示效果
This commit is contained in:
@@ -85,7 +85,8 @@
|
||||
try {
|
||||
const response = await axios.get(`/api/wx_logs?type=${this.logType}&lines=${this.logLines}`);
|
||||
if (response.data.success) {
|
||||
this.logContent = response.data.data.content || [];
|
||||
// 解析文本日志行为对象数组
|
||||
this.logContent = this.parseLogLines(response.data.data.content || []);
|
||||
this.filterLogs();
|
||||
this.scrollToBottom();
|
||||
} else {
|
||||
@@ -98,6 +99,21 @@
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
parseLogLines(lines) {
|
||||
return lines.map(line => {
|
||||
// 解析日志行,格式如:2025-05-28 17:10:04.758 | INFO | module:func:line - message
|
||||
const parts = line.split(' | ');
|
||||
if (parts.length < 4) {
|
||||
return { timestamp: '', level: '', message: line }; // 格式不正确时保留原始行
|
||||
}
|
||||
const [timestamp, level, , message] = parts;
|
||||
return {
|
||||
timestamp: timestamp.trim(),
|
||||
level: level.trim(),
|
||||
message: message.trim()
|
||||
};
|
||||
}).filter(log => log.timestamp && log.level && log.message); // 过滤无效日志
|
||||
},
|
||||
filterLogs() {
|
||||
if (!this.searchQuery) {
|
||||
this.filteredLogs = this.logContent;
|
||||
@@ -113,10 +129,14 @@
|
||||
},
|
||||
formatTimestamp(timestamp) {
|
||||
if (!timestamp) return '';
|
||||
return new Date(timestamp).toLocaleString('zh-CN', {
|
||||
year: 'numeric', month: '2-digit', day: '2-digit',
|
||||
hour: '2-digit', minute: '2-digit', second: '2-digit'
|
||||
});
|
||||
try {
|
||||
return new Date(timestamp).toLocaleString('zh-CN', {
|
||||
year: 'numeric', month: '2-digit', day: '2-digit',
|
||||
hour: '2-digit', minute: '2-digit', second: '2-digit'
|
||||
});
|
||||
} catch (e) {
|
||||
return timestamp; // 解析失败时返回原始时间戳
|
||||
}
|
||||
},
|
||||
scrollToBottom() {
|
||||
if (this.autoScroll) {
|
||||
|
||||
Reference in New Issue
Block a user