From 76516336afa302d7136c87782f9d963cf50dfafb Mon Sep 17 00:00:00 2001
From: JianYu Zheng <2375294554@qq.com>
Date: Mon, 11 Aug 2025 16:20:46 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E6=8B=86=E5=88=86te?=
=?UTF-8?q?st=5Fpage.html,=E6=8A=8A=E6=97=A5=E5=BF=97=E5=87=BD=E6=95=B0?=
=?UTF-8?q?=E6=8F=90=E5=8F=96=E5=87=BA=E6=9D=A5=EF=BC=8C=E5=87=8F=E5=B0=91?=
=?UTF-8?q?=E5=8D=95=E4=B8=AA=E6=96=87=E4=BB=B6=E5=A4=A7=E5=B0=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
main/xiaozhi-server/test/js/utils/logger.js | 34 ++++++++++++++++++
main/xiaozhi-server/test/test_page.html | 38 ++-------------------
2 files changed, 36 insertions(+), 36 deletions(-)
create mode 100644 main/xiaozhi-server/test/js/utils/logger.js
diff --git a/main/xiaozhi-server/test/js/utils/logger.js b/main/xiaozhi-server/test/js/utils/logger.js
new file mode 100644
index 00000000..38e43150
--- /dev/null
+++ b/main/xiaozhi-server/test/js/utils/logger.js
@@ -0,0 +1,34 @@
+const logContainer = document.getElementById('logContainer');
+export function log(message, type = 'info') {
+ // 将消息按换行符分割成多行
+ const lines = message.split('\n');
+ const now = new Date();
+ // const timestamp = `[${now.toLocaleTimeString()}] `;
+ const timestamp = `[${now.toLocaleTimeString()}.${now.getMilliseconds().toString().padStart(3, '0')}] `;
+ // 为每一行创建日志条目
+ lines.forEach((line, index) => {
+ const logEntry = document.createElement('div');
+ logEntry.className = `log-entry log-${type}`;
+ // 如果是第一条日志,显示时间戳
+ const prefix = index === 0 ? timestamp : ' '.repeat(timestamp.length);
+ logEntry.textContent = `${prefix}${line}`;
+ // logEntry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
+ // logEntry.style 保留起始的空格
+ logEntry.style.whiteSpace = 'pre';
+ if (type === 'error') {
+ logEntry.style.color = 'red';
+ } else if (type === 'debug') {
+ logEntry.style.color = 'gray';
+ return;
+ } else if (type === 'warning') {
+ logEntry.style.color = 'orange';
+ } else if (type === 'success') {
+ logEntry.style.color = 'green';
+ } else {
+ logEntry.style.color = 'black';
+ }
+ logContainer.appendChild(logEntry);
+ });
+
+ logContainer.scrollTop = logContainer.scrollHeight;
+}
\ No newline at end of file
diff --git a/main/xiaozhi-server/test/test_page.html b/main/xiaozhi-server/test/test_page.html
index ec9a5f4b..8eaad778 100644
--- a/main/xiaozhi-server/test/test_page.html
+++ b/main/xiaozhi-server/test/test_page.html
@@ -99,7 +99,8 @@
-