From e05e7fc1d2eac86bb02caf92e8a6a446d7474267 Mon Sep 17 00:00:00 2001 From: liuwei Date: Wed, 28 May 2025 17:16:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96log=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/dashboard/templates/wx_logs.html | 30 +++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/admin/dashboard/templates/wx_logs.html b/admin/dashboard/templates/wx_logs.html index 363cbd1..321d37d 100644 --- a/admin/dashboard/templates/wx_logs.html +++ b/admin/dashboard/templates/wx_logs.html @@ -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) {