优化log显示效果
This commit is contained in:
@@ -85,7 +85,8 @@
|
|||||||
try {
|
try {
|
||||||
const response = await axios.get(`/api/wx_logs?type=${this.logType}&lines=${this.logLines}`);
|
const response = await axios.get(`/api/wx_logs?type=${this.logType}&lines=${this.logLines}`);
|
||||||
if (response.data.success) {
|
if (response.data.success) {
|
||||||
this.logContent = response.data.data.content || [];
|
// 解析文本日志行为对象数组
|
||||||
|
this.logContent = this.parseLogLines(response.data.data.content || []);
|
||||||
this.filterLogs();
|
this.filterLogs();
|
||||||
this.scrollToBottom();
|
this.scrollToBottom();
|
||||||
} else {
|
} else {
|
||||||
@@ -98,6 +99,21 @@
|
|||||||
this.loading = false;
|
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() {
|
filterLogs() {
|
||||||
if (!this.searchQuery) {
|
if (!this.searchQuery) {
|
||||||
this.filteredLogs = this.logContent;
|
this.filteredLogs = this.logContent;
|
||||||
@@ -113,10 +129,14 @@
|
|||||||
},
|
},
|
||||||
formatTimestamp(timestamp) {
|
formatTimestamp(timestamp) {
|
||||||
if (!timestamp) return '';
|
if (!timestamp) return '';
|
||||||
return new Date(timestamp).toLocaleString('zh-CN', {
|
try {
|
||||||
year: 'numeric', month: '2-digit', day: '2-digit',
|
return new Date(timestamp).toLocaleString('zh-CN', {
|
||||||
hour: '2-digit', minute: '2-digit', second: '2-digit'
|
year: 'numeric', month: '2-digit', day: '2-digit',
|
||||||
});
|
hour: '2-digit', minute: '2-digit', second: '2-digit'
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
return timestamp; // 解析失败时返回原始时间戳
|
||||||
|
}
|
||||||
},
|
},
|
||||||
scrollToBottom() {
|
scrollToBottom() {
|
||||||
if (this.autoScroll) {
|
if (this.autoScroll) {
|
||||||
|
|||||||
Reference in New Issue
Block a user