diff --git a/astrbot/core/log.py b/astrbot/core/log.py index 501f0012e..e1e2cde2e 100644 --- a/astrbot/core/log.py +++ b/astrbot/core/log.py @@ -108,11 +108,12 @@ class LogBroker: """ self.subscribers.remove(q) - def publish(self, log_entry: str): + def publish(self, log_entry: dict): """发布新日志到所有订阅者, 使用非阻塞方式投递, 避免一个订阅者阻塞整个系统 Args: - log_entry (str): 日志消息, 可以是字符串或字典 + log_entry (dict): 日志消息, 包含日志级别和日志内容. + example: {"level": "INFO", "data": "This is a log message.", "time": "2023-10-01 12:00:00"} """ self.log_cache.append(log_entry) for q in self.subscribers: @@ -140,7 +141,11 @@ class LogQueueHandler(logging.Handler): record (logging.LogRecord): 日志记录对象, 包含日志信息 """ log_entry = self.format(record) - self.log_broker.publish(log_entry) + self.log_broker.publish({ + "level": record.levelname, + "time": record.asctime, + "data": log_entry, + }) class LogManager: diff --git a/astrbot/dashboard/routes/log.py b/astrbot/dashboard/routes/log.py index b1c68722c..6f3940c0a 100644 --- a/astrbot/dashboard/routes/log.py +++ b/astrbot/dashboard/routes/log.py @@ -20,7 +20,7 @@ class LogRoute(Route): message = await queue.get() payload = { "type": "log", - "data": message, + **message # see astrbot/core/log.py } yield f"data: {json.dumps(payload, ensure_ascii=False)}\n\n" except asyncio.CancelledError: diff --git a/dashboard/src/components/shared/ConsoleDisplayer.vue b/dashboard/src/components/shared/ConsoleDisplayer.vue index dfee44ce9..e780d6569 100644 --- a/dashboard/src/components/shared/ConsoleDisplayer.vue +++ b/dashboard/src/components/shared/ConsoleDisplayer.vue @@ -3,9 +3,20 @@ import { useCommonStore } from '@/stores/common'; \ No newline at end of file + + + \ No newline at end of file diff --git a/dashboard/src/stores/common.js b/dashboard/src/stores/common.js index f983115ca..c4b90b8d2 100644 --- a/dashboard/src/stores/common.js +++ b/dashboard/src/stores/common.js @@ -71,8 +71,8 @@ export const useCommonStore = defineStore({ let data_json = JSON.parse(data) if (data_json.type === 'log') { - let log = data_json.data - this.log_cache.push(log); + // let log = data_json.data + this.log_cache.push(data_json); if (this.log_cache.length > this.log_cache_max_len) { this.log_cache.shift(); } diff --git a/dashboard/src/views/ConsolePage.vue b/dashboard/src/views/ConsolePage.vue index e638df47c..2ac9b3a73 100644 --- a/dashboard/src/views/ConsolePage.vue +++ b/dashboard/src/views/ConsolePage.vue @@ -44,7 +44,7 @@ import axios from 'axios'; - +