From 12de69fb3c9ab5458d8611265a6d3bfde24e270a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A2=A8=E6=A2=93=E6=9F=92?= <1787882683@qq.com>
Date: Thu, 24 Apr 2025 11:21:07 +0800
Subject: [PATCH] =?UTF-8?q?feat(logger):=20=E4=B8=BA=E8=81=8A=E5=A4=A9?=
=?UTF-8?q?=E6=B5=81=E6=A8=A1=E5=9D=97=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A?=
=?UTF-8?q?=E4=B9=89=E6=97=A5=E5=BF=97=E9=85=8D=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
新增 `CHAT_STREAM_STYLE_CONFIG` 配置,用于定义聊天流模块的日志格式,包括控制台和文件输出的样式。同时更新 `chat_stream.py` 以使用该配置,确保日志输出风格一致且易于识别。
---
src/common/logger.py | 19 +++++++++++++++++++
src/plugins/chat/chat_stream.py | 9 +++++++--
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/src/common/logger.py b/src/common/logger.py
index 62dbfb051..ec2c887a5 100644
--- a/src/common/logger.py
+++ b/src/common/logger.py
@@ -349,6 +349,24 @@ BASE_TOOL_STYLE_CONFIG = {
},
}
+CHAT_STREAM_STYLE_CONFIG = {
+ "advanced": {
+ "console_format": (
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
+ "聊天流 | "
+ "{message}"
+ ),
+ "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 聊天流 | {message}",
+ },
+ "simple": {
+ "console_format": (
+ "{time:MM-DD HH:mm} | 聊天流 | {message}"
+ ),
+ "file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 聊天流 | {message}",
+ },
+}
+
PERSON_INFO_STYLE_CONFIG = {
"advanced": {
"console_format": (
@@ -526,6 +544,7 @@ BACKGROUND_TASKS_STYLE_CONFIG = (
BACKGROUND_TASKS_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else BACKGROUND_TASKS_STYLE_CONFIG["advanced"]
)
MEMORY_STYLE_CONFIG = MEMORY_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else MEMORY_STYLE_CONFIG["advanced"]
+CHAT_STREAM_STYLE_CONFIG = CHAT_STREAM_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else CHAT_STREAM_STYLE_CONFIG["advanced"]
TOPIC_STYLE_CONFIG = TOPIC_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else TOPIC_STYLE_CONFIG["advanced"]
SENDER_STYLE_CONFIG = SENDER_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else SENDER_STYLE_CONFIG["advanced"]
LLM_STYLE_CONFIG = LLM_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else LLM_STYLE_CONFIG["advanced"]
diff --git a/src/plugins/chat/chat_stream.py b/src/plugins/chat/chat_stream.py
index ebeaa7c0f..e50dc3ec2 100644
--- a/src/plugins/chat/chat_stream.py
+++ b/src/plugins/chat/chat_stream.py
@@ -8,9 +8,14 @@ from typing import Dict, Optional
from ...common.database import db
from ..message.message_base import GroupInfo, UserInfo
-from src.common.logger import get_module_logger
+from src.common.logger import get_module_logger, LogConfig, CHAT_STREAM_STYLE_CONFIG
-logger = get_module_logger("chat_stream")
+chat_stream_log_config = LogConfig(
+ console_format=CHAT_STREAM_STYLE_CONFIG["console_format"],
+ file_format=CHAT_STREAM_STYLE_CONFIG["file_format"],
+)
+
+logger = get_module_logger("chat_stream", config=chat_stream_log_config)
class ChatStream: