From 7438c2dd76a367a5a3ded5b2f462e3a05b10436f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A2=A8=E6=A2=93=E6=9F=92?= <1787882683@qq.com>
Date: Wed, 23 Apr 2025 22:27:44 +0800
Subject: [PATCH 1/8] =?UTF-8?q?refactor(logger):=20=E6=9B=BF=E6=8D=A2print?=
=?UTF-8?q?=E4=B8=BAlogger=E5=B9=B6=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=AE=9A?=
=?UTF-8?q?=E4=B9=89=E6=97=A5=E5=BF=97=E6=A0=B7=E5=BC=8F=E6=94=AF=E6=8C=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
将配置文件加载中的print语句替换为logger.info,以统一日志输出。同时新增log_decorators.py文件,提供自定义日志样式的装饰器支持,并在logger.py中实现自定义样式处理器的添加和移除功能。
---
src/common/log_decorators.py | 107 ++++++++++++++
src/common/logger.py | 189 +++++++++++++++++-------
src/plugins/knowledge/src/lpmmconfig.py | 5 +-
3 files changed, 245 insertions(+), 56 deletions(-)
create mode 100644 src/common/log_decorators.py
diff --git a/src/common/log_decorators.py b/src/common/log_decorators.py
new file mode 100644
index 000000000..60d9c6cc9
--- /dev/null
+++ b/src/common/log_decorators.py
@@ -0,0 +1,107 @@
+import functools
+import inspect
+from typing import Callable, Any
+from .logger import logger, add_custom_style_handler
+
+
+def use_log_style(
+ style_name: str,
+ console_format: str,
+ console_level: str = "INFO",
+ # file_format: Optional[str] = None, # 暂未支持文件输出
+ # file_level: str = "DEBUG",
+) -> Callable:
+ """装饰器:为函数内的日志启用特定的自定义样式。
+
+ Args:
+ style_name (str): 自定义样式的唯一名称。
+ console_format (str): 控制台输出的格式字符串。
+ console_level (str, optional): 控制台日志级别. Defaults to "INFO".
+ # file_format (Optional[str], optional): 文件输出格式 (暂未支持). Defaults to None.
+ # file_level (str, optional): 文件日志级别 (暂未支持). Defaults to "DEBUG".
+
+ Returns:
+ Callable: 返回装饰器本身。
+ """
+
+ def decorator(func: Callable) -> Callable:
+ # 获取被装饰函数所在的模块名
+ module = inspect.getmodule(func)
+ if module is None:
+ # 如果无法获取模块(例如,在交互式解释器中定义函数),则使用默认名称
+ module_name = "unknown_module"
+ logger.warning(f"无法确定函数 {func.__name__} 的模块,将使用 '{module_name}'")
+ else:
+ module_name = module.__name__
+
+ # 在函数首次被调用(或模块加载时)确保自定义处理器已添加
+ # 注意:这会在模块加载时执行,而不是每次函数调用时
+ # print(f"Setting up custom style '{style_name}' for module '{module_name}' in decorator definition")
+ add_custom_style_handler(
+ module_name=module_name,
+ style_name=style_name,
+ console_format=console_format,
+ console_level=console_level,
+ # file_format=file_format,
+ # file_level=file_level,
+ )
+
+ @functools.wraps(func)
+ def wrapper(*args: Any, **kwargs: Any) -> Any:
+ # 创建绑定了模块名和自定义样式标记的 logger 实例
+ custom_logger = logger.bind(module=module_name, custom_style=style_name)
+ # print(f"Executing {func.__name__} with custom logger for style '{style_name}'")
+ # 将自定义 logger 作为第一个参数传递给原函数
+ # 注意:这要求被装饰的函数第一个参数用于接收 logger
+ try:
+ return func(custom_logger, *args, **kwargs)
+ except TypeError as e:
+ # 捕获可能的类型错误,比如原函数不接受 logger 参数
+ logger.error(
+ f"调用 {func.__name__} 时出错:请确保该函数接受一个 logger 实例作为其第一个参数。错误:{e}"
+ )
+ # 可以选择重新抛出异常或返回特定值
+ raise e
+
+ return wrapper
+
+ return decorator
+
+
+# --- 示例用法 (可以在其他模块中这样使用) ---
+
+# # 假设这是你的模块 my_module.py
+# from src.common.log_decorators import use_log_style
+# from src.common.logger import get_module_logger, LoguruLogger
+
+# # 获取模块的标准 logger
+# standard_logger = get_module_logger(__name__)
+
+# # 定义一个自定义样式
+# MY_SPECIAL_STYLE = "special"
+# MY_SPECIAL_FORMAT = " SPECIAL [{time:HH:mm:ss}] | {message}"
+
+# @use_log_style(style_name=MY_SPECIAL_STYLE, console_format=MY_SPECIAL_FORMAT)
+# def my_function_with_special_logs(custom_logger: LoguruLogger, x: int, y: int):
+# standard_logger.info("这是一条使用标准格式的日志")
+# custom_logger.info(f"开始执行特殊操作,参数: x={x}, y={y}")
+# result = x + y
+# custom_logger.success(f"特殊操作完成,结果: {result}")
+# standard_logger.info("标准格式日志:函数即将结束")
+# return result
+
+# @use_log_style(style_name="another_style", console_format="任务: {message}")
+# def another_task(task_logger: LoguruLogger, task_name: str):
+# standard_logger.debug("准备执行另一个任务")
+# task_logger.info(f"正在处理任务 '{task_name}'")
+# # ... 执行任务 ...
+# task_logger.warning("任务处理中遇到一个警告")
+# standard_logger.info("另一个任务的标准日志")
+
+# if __name__ == "__main__":
+# print("\n--- 调用 my_function_with_special_logs ---")
+# my_function_with_special_logs(10, 5)
+# print("\n--- 调用 another_task ---")
+# another_task("数据清理")
+# print("\n--- 单独使用标准 logger ---")
+# standard_logger.info("这是一条完全独立的标准日志")
\ No newline at end of file
diff --git a/src/common/logger.py b/src/common/logger.py
index 2b2208419..cbc6c1499 100644
--- a/src/common/logger.py
+++ b/src/common/logger.py
@@ -1,5 +1,5 @@
from loguru import logger
-from typing import Dict, Optional, Union, List
+from typing import Dict, Optional, Union, List, Tuple
import sys
import os
from types import ModuleType
@@ -26,6 +26,7 @@ LoguruLogger = logger.__class__
# 全局注册表:记录模块与处理器ID的映射
_handler_registry: Dict[str, List[int]] = {}
+_custom_style_handlers: Dict[Tuple[str, str], List[int]] = {} # 记录自定义样式处理器ID
# 获取日志存储根地址
current_file_path = Path(__file__).resolve()
@@ -42,8 +43,7 @@ if not SIMPLE_OUTPUT:
"file_level": "DEBUG",
# 格式配置
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
"{extra[module]: <12} | "
"{message}"
),
@@ -59,7 +59,7 @@ else:
"console_level": "INFO",
"file_level": "DEBUG",
# 格式配置
- "console_format": "{time:MM-DD HH:mm} | {extra[module]} | {message}",
+ "console_format": "{time:MM-DD HH:mm} | {extra[module]} | {message}",
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | {message}",
"log_dir": LOG_ROOT,
"rotation": "00:00",
@@ -72,8 +72,8 @@ else:
MEMORY_STYLE_CONFIG = {
"advanced": {
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
"{extra[module]: <12} | "
"海马体 | "
"{message}"
@@ -82,7 +82,7 @@ MEMORY_STYLE_CONFIG = {
},
"simple": {
"console_format": (
- "{time:MM-DD HH:mm} | 海马体 | {message}"
+ "{time:MM-DD HH:mm} | 海马体 | {message}"
),
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 海马体 | {message}",
},
@@ -92,8 +92,8 @@ MEMORY_STYLE_CONFIG = {
PFC_STYLE_CONFIG = {
"advanced": {
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
"{extra[module]: <12} | "
"PFC | "
"{message}"
@@ -102,7 +102,7 @@ PFC_STYLE_CONFIG = {
},
"simple": {
"console_format": (
- "{time:MM-DD HH:mm} | PFC | {message}"
+ "{time:MM-DD HH:mm} | PFC | {message}"
),
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | PFC | {message}",
},
@@ -112,8 +112,8 @@ PFC_STYLE_CONFIG = {
MOOD_STYLE_CONFIG = {
"advanced": {
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
"{extra[module]: <12} | "
"心情 | "
"{message}"
@@ -121,7 +121,7 @@ MOOD_STYLE_CONFIG = {
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 心情 | {message}",
},
"simple": {
- "console_format": "{time:MM-DD HH:mm} | 心情 | {message}",
+ "console_format": "{time:MM-DD HH:mm} | 心情 | {message}",
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 心情 | {message}",
},
}
@@ -129,8 +129,8 @@ MOOD_STYLE_CONFIG = {
TOOL_USE_STYLE_CONFIG = {
"advanced": {
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
"{extra[module]: <12} | "
"工具使用 | "
"{message}"
@@ -138,7 +138,7 @@ TOOL_USE_STYLE_CONFIG = {
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 工具使用 | {message}",
},
"simple": {
- "console_format": "{time:MM-DD HH:mm} | 工具使用 | {message}",
+ "console_format": "{time:MM-DD HH:mm} | 工具使用 | {message}",
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 工具使用 | {message}",
},
}
@@ -148,8 +148,8 @@ TOOL_USE_STYLE_CONFIG = {
RELATION_STYLE_CONFIG = {
"advanced": {
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
"{extra[module]: <12} | "
"关系 | "
"{message}"
@@ -157,7 +157,7 @@ RELATION_STYLE_CONFIG = {
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 关系 | {message}",
},
"simple": {
- "console_format": "{time:MM-DD HH:mm} | 关系 | {message}",
+ "console_format": "{time:MM-DD HH:mm} | 关系 | {message}",
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 关系 | {message}",
},
}
@@ -166,8 +166,8 @@ RELATION_STYLE_CONFIG = {
CONFIG_STYLE_CONFIG = {
"advanced": {
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
"{extra[module]: <12} | "
"配置 | "
"{message}"
@@ -175,7 +175,7 @@ CONFIG_STYLE_CONFIG = {
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 配置 | {message}",
},
"simple": {
- "console_format": "{time:MM-DD HH:mm} | 配置 | {message}",
+ "console_format": "{time:MM-DD HH:mm} | 配置 | {message}",
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 配置 | {message}",
},
}
@@ -183,8 +183,8 @@ CONFIG_STYLE_CONFIG = {
SENDER_STYLE_CONFIG = {
"advanced": {
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
"{extra[module]: <12} | "
"消息发送 | "
"{message}"
@@ -192,7 +192,7 @@ SENDER_STYLE_CONFIG = {
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 消息发送 | {message}",
},
"simple": {
- "console_format": "{time:MM-DD HH:mm} | 消息发送 | {message}",
+ "console_format": "{time:MM-DD HH:mm} | 消息发送 | {message}",
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 消息发送 | {message}",
},
}
@@ -200,8 +200,8 @@ SENDER_STYLE_CONFIG = {
HEARTFLOW_STYLE_CONFIG = {
"advanced": {
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
"{extra[module]: <12} | "
"麦麦大脑袋 | "
"{message}"
@@ -210,7 +210,7 @@ HEARTFLOW_STYLE_CONFIG = {
},
"simple": {
"console_format": (
- "{time:MM-DD HH:mm} | 麦麦大脑袋 | {message}"
+ "{time:MM-DD HH:mm} | 麦麦大脑袋 | {message}"
), # noqa: E501
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦大脑袋 | {message}",
},
@@ -219,8 +219,8 @@ HEARTFLOW_STYLE_CONFIG = {
SCHEDULE_STYLE_CONFIG = {
"advanced": {
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
"{extra[module]: <12} | "
"在干嘛 | "
"{message}"
@@ -228,7 +228,7 @@ SCHEDULE_STYLE_CONFIG = {
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 在干嘛 | {message}",
},
"simple": {
- "console_format": "{time:MM-DD HH:mm} | 在干嘛 | {message}",
+ "console_format": "{time:MM-DD HH:mm} | 在干嘛 | {message}",
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 在干嘛 | {message}",
},
}
@@ -236,8 +236,8 @@ SCHEDULE_STYLE_CONFIG = {
LLM_STYLE_CONFIG = {
"advanced": {
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
"{extra[module]: <12} | "
"麦麦组织语言 | "
"{message}"
@@ -245,7 +245,7 @@ LLM_STYLE_CONFIG = {
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦组织语言 | {message}",
},
"simple": {
- "console_format": "{time:MM-DD HH:mm} | 麦麦组织语言 | {message}",
+ "console_format": "{time:MM-DD HH:mm} | 麦麦组织语言 | {message}",
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦组织语言 | {message}",
},
}
@@ -255,8 +255,8 @@ LLM_STYLE_CONFIG = {
TOPIC_STYLE_CONFIG = {
"advanced": {
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
"{extra[module]: <12} | "
"话题 | "
"{message}"
@@ -264,7 +264,7 @@ TOPIC_STYLE_CONFIG = {
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 话题 | {message}",
},
"simple": {
- "console_format": "{time:MM-DD HH:mm} | 主题 | {message}",
+ "console_format": "{time:MM-DD HH:mm} | 主题 | {message}",
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 话题 | {message}",
},
}
@@ -273,8 +273,8 @@ TOPIC_STYLE_CONFIG = {
CHAT_STYLE_CONFIG = {
"advanced": {
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
"{extra[module]: <12} | "
"见闻 | "
"{message}"
@@ -283,7 +283,7 @@ CHAT_STYLE_CONFIG = {
},
"simple": {
"console_format": (
- "{time:MM-DD HH:mm} | 见闻 | {message}"
+ "{time:MM-DD HH:mm} | 见闻 | {message}"
), # noqa: E501
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 见闻 | {message}",
},
@@ -292,8 +292,8 @@ CHAT_STYLE_CONFIG = {
SUB_HEARTFLOW_STYLE_CONFIG = {
"advanced": {
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
"{extra[module]: <12} | "
"麦麦小脑袋 | "
"{message}"
@@ -302,7 +302,7 @@ SUB_HEARTFLOW_STYLE_CONFIG = {
},
"simple": {
"console_format": (
- "{time:MM-DD HH:mm} | 麦麦小脑袋 | {message}"
+ "{time:MM-DD HH:mm} | 麦麦小脑袋 | {message}"
), # noqa: E501
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦小脑袋 | {message}",
},
@@ -311,8 +311,8 @@ SUB_HEARTFLOW_STYLE_CONFIG = {
WILLING_STYLE_CONFIG = {
"advanced": {
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
"{extra[module]: <12} | "
"意愿 | "
"{message}"
@@ -320,7 +320,7 @@ WILLING_STYLE_CONFIG = {
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 意愿 | {message}",
},
"simple": {
- "console_format": "{time:MM-DD HH:mm} | 意愿 | {message} ", # noqa: E501
+ "console_format": "{time:MM-DD HH:mm} | 意愿 | {message} ", # noqa: E501
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 意愿 | {message}",
},
}
@@ -329,8 +329,8 @@ WILLING_STYLE_CONFIG = {
MAI_STATE_CONFIG = {
"advanced": {
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
"{extra[module]: <12} | "
"麦麦状态 | "
"{message}"
@@ -338,7 +338,7 @@ MAI_STATE_CONFIG = {
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦状态 | {message}",
},
"simple": {
- "console_format": "{time:MM-DD HH:mm} | 麦麦状态 | {message} ", # noqa: E501
+ "console_format": "{time:MM-DD HH:mm} | 麦麦状态 | {message} ", # noqa: E501
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | 麦麦状态 | {message}",
},
}
@@ -347,8 +347,8 @@ MAI_STATE_CONFIG = {
LPMM_STYLE_CONFIG = {
"advanced": {
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
+ "{time:YYYY-MM-DD HH:mm:ss} | "
+ "{level: <8} | "
"{extra[module]: <12} | "
"LPMM | "
"{message}"
@@ -357,7 +357,7 @@ LPMM_STYLE_CONFIG = {
},
"simple": {
"console_format": (
- "{time:MM-DD HH:mm} | LPMM | {message}"
+ "{time:MM-DD HH:mm} | LPMM | {message}"
),
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | LPMM | {message}",
},
@@ -451,7 +451,7 @@ def get_module_logger(
sink=sys.stderr,
level=os.getenv("CONSOLE_LOG_LEVEL", console_level or current_config["console_level"]),
format=current_config["console_format"],
- filter=lambda record: record["extra"].get("module") == module_name,
+ filter=lambda record: record["extra"].get("module") == module_name and 'custom_style' not in record['extra'],
enqueue=True,
)
handler_ids.append(console_id)
@@ -470,7 +470,7 @@ def get_module_logger(
retention=current_config["retention"],
compression=current_config["compression"],
encoding="utf-8",
- filter=lambda record: record["extra"].get("module") == module_name,
+ filter=lambda record: record["extra"].get("module") == module_name and 'custom_style' not in record['extra'],
enqueue=True,
)
handler_ids.append(file_id)
@@ -487,6 +487,87 @@ def get_module_logger(
return logger.bind(module=module_name)
+def add_custom_style_handler(
+ module_name: str,
+ style_name: str,
+ console_format: str,
+ console_level: str = "INFO",
+ # file_format: Optional[str] = None, # 暂时只支持控制台
+ # file_level: str = "DEBUG",
+ # config: Optional[LogConfig] = None, # 暂时不使用全局配置
+) -> None:
+ """为指定模块和样式名添加自定义日志处理器(目前仅支持控制台)."""
+ handler_key = (module_name, style_name)
+
+ # 如果已存在该模块和样式的处理器,则不重复添加
+ if handler_key in _custom_style_handlers:
+ # print(f"Custom handler for {handler_key} already exists.")
+ return
+
+ handler_ids = []
+
+ # 添加自定义控制台处理器
+ try:
+ custom_console_id = logger.add(
+ sink=sys.stderr,
+ level=os.getenv(f"{module_name.upper()}_{style_name.upper()}_CONSOLE_LEVEL", console_level),
+ format=console_format,
+ filter=lambda record: record["extra"].get("module") == module_name
+ and record["extra"].get("custom_style") == style_name,
+ enqueue=True,
+ )
+ handler_ids.append(custom_console_id)
+ # print(f"Added custom console handler {custom_console_id} for {handler_key}")
+ except Exception as e:
+ logger.error(f"Failed to add custom console handler for {handler_key}: {e}")
+ # 如果添加失败,确保列表为空,避免记录不存在的ID
+ handler_ids = []
+
+ # # 文件处理器 (可选,按需启用)
+ # if file_format:
+ # current_config = config.config if config else DEFAULT_CONFIG
+ # log_dir = Path(current_config["log_dir"])
+ # log_dir.mkdir(parents=True, exist_ok=True)
+ # # 可以考虑将自定义样式的日志写入单独文件或模块主文件
+ # log_file = log_dir / module_name / f"{style_name}_{{time:YYYY-MM-DD}}.log"
+ # log_file.parent.mkdir(parents=True, exist_ok=True)
+ # try:
+ # custom_file_id = logger.add(
+ # sink=str(log_file),
+ # level=os.getenv(f"{module_name.upper()}_{style_name.upper()}_FILE_LEVEL", file_level),
+ # format=file_format,
+ # rotation=current_config["rotation"],
+ # retention=current_config["retention"],
+ # compression=current_config["compression"],
+ # encoding="utf-8",
+ # filter=lambda record: record["extra"].get("module") == module_name
+ # and record["extra"].get("custom_style") == style_name,
+ # enqueue=True,
+ # )
+ # handler_ids.append(custom_file_id)
+ # except Exception as e:
+ # logger.error(f"Failed to add custom file handler for {handler_key}: {e}")
+
+ # 更新自定义处理器注册表
+ if handler_ids:
+ _custom_style_handlers[handler_key] = handler_ids
+
+
+def remove_custom_style_handler(module_name: str, style_name: str) -> None:
+ """移除指定模块和样式名的自定义日志处理器."""
+ handler_key = (module_name, style_name)
+ if handler_key in _custom_style_handlers:
+ for handler_id in _custom_style_handlers[handler_key]:
+ try:
+ logger.remove(handler_id)
+ # print(f"Removed custom handler {handler_id} for {handler_key}")
+ except ValueError:
+ # 可能已经被移除或不存在
+ # print(f"Handler {handler_id} for {handler_key} already removed or invalid.")
+ pass
+ del _custom_style_handlers[handler_key]
+
+
def remove_module_logger(module_name: str) -> None:
"""清理指定模块的日志处理器"""
if module_name in _handler_registry:
diff --git a/src/plugins/knowledge/src/lpmmconfig.py b/src/plugins/knowledge/src/lpmmconfig.py
index 7f59bc897..753562f45 100644
--- a/src/plugins/knowledge/src/lpmmconfig.py
+++ b/src/plugins/knowledge/src/lpmmconfig.py
@@ -2,6 +2,7 @@ import os
import toml
import sys
import argparse
+from .global_logger import logger
PG_NAMESPACE = "paragraph"
ENT_NAMESPACE = "entity"
@@ -63,8 +64,8 @@ def _load_config(config, config_file_path):
if "persistence" in file_config:
config["persistence"] = file_config["persistence"]
- print(config)
- print("Configurations loaded from file: ", config_file_path)
+ # print(config)
+ logger.info(f"从文件中读取配置: {config_file_path}")
parser = argparse.ArgumentParser(description="Configurations for the pipeline")
From b0b05d532bf3553a5f641526fd6147248bb11f76 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
Date: Wed, 23 Apr 2025 14:27:57 +0000
Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=A4=96=20=E8=87=AA=E5=8A=A8=E6=A0=BC?=
=?UTF-8?q?=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81=20[skip=20ci]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/common/log_decorators.py | 2 +-
src/common/logger.py | 10 ++++------
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/src/common/log_decorators.py b/src/common/log_decorators.py
index 60d9c6cc9..9838717f9 100644
--- a/src/common/log_decorators.py
+++ b/src/common/log_decorators.py
@@ -104,4 +104,4 @@ def use_log_style(
# print("\n--- 调用 another_task ---")
# another_task("数据清理")
# print("\n--- 单独使用标准 logger ---")
-# standard_logger.info("这是一条完全独立的标准日志")
\ No newline at end of file
+# standard_logger.info("这是一条完全独立的标准日志")
diff --git a/src/common/logger.py b/src/common/logger.py
index cbc6c1499..df075d47b 100644
--- a/src/common/logger.py
+++ b/src/common/logger.py
@@ -26,7 +26,7 @@ LoguruLogger = logger.__class__
# 全局注册表:记录模块与处理器ID的映射
_handler_registry: Dict[str, List[int]] = {}
-_custom_style_handlers: Dict[Tuple[str, str], List[int]] = {} # 记录自定义样式处理器ID
+_custom_style_handlers: Dict[Tuple[str, str], List[int]] = {} # 记录自定义样式处理器ID
# 获取日志存储根地址
current_file_path = Path(__file__).resolve()
@@ -43,9 +43,7 @@ if not SIMPLE_OUTPUT:
"file_level": "DEBUG",
# 格式配置
"console_format": (
- "{time:YYYY-MM-DD HH:mm:ss} | "
- "{extra[module]: <12} | "
- "{message}"
+ "{time:YYYY-MM-DD HH:mm:ss} | {extra[module]: <12} | {message}"
),
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | {message}",
"log_dir": LOG_ROOT,
@@ -451,7 +449,7 @@ def get_module_logger(
sink=sys.stderr,
level=os.getenv("CONSOLE_LOG_LEVEL", console_level or current_config["console_level"]),
format=current_config["console_format"],
- filter=lambda record: record["extra"].get("module") == module_name and 'custom_style' not in record['extra'],
+ filter=lambda record: record["extra"].get("module") == module_name and "custom_style" not in record["extra"],
enqueue=True,
)
handler_ids.append(console_id)
@@ -470,7 +468,7 @@ def get_module_logger(
retention=current_config["retention"],
compression=current_config["compression"],
encoding="utf-8",
- filter=lambda record: record["extra"].get("module") == module_name and 'custom_style' not in record['extra'],
+ filter=lambda record: record["extra"].get("module") == module_name and "custom_style" not in record["extra"],
enqueue=True,
)
handler_ids.append(file_id)
From 44a7058985d31644ab7497f8575c2181a09c35bc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A2=A8=E6=A2=93=E6=9F=92?= <1787882683@qq.com>
Date: Wed, 23 Apr 2025 22:43:17 +0800
Subject: [PATCH 3/8] =?UTF-8?q?refactor(common):=20=E4=BC=98=E5=8C=96=20SI?=
=?UTF-8?q?MPLE=5FOUTPUT=20=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E8=AF=BB?=
=?UTF-8?q?=E5=8F=96=E9=80=BB=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 将 SIMPLE_OUTPUT环境变量的值转换为布尔型
- 提高代码可读性和健壮性
---
src/common/logger.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/common/logger.py b/src/common/logger.py
index df075d47b..740da43b0 100644
--- a/src/common/logger.py
+++ b/src/common/logger.py
@@ -33,6 +33,10 @@ current_file_path = Path(__file__).resolve()
LOG_ROOT = "logs"
SIMPLE_OUTPUT = os.getenv("SIMPLE_OUTPUT", "false")
+if SIMPLE_OUTPUT == "true" or SIMPLE_OUTPUT == "True":
+ SIMPLE_OUTPUT = True
+else:
+ SIMPLE_OUTPUT = False
print(f"SIMPLE_OUTPUT: {SIMPLE_OUTPUT}")
if not SIMPLE_OUTPUT:
From 95cacee2bd506ce62065c002c93c661e4798fb96 Mon Sep 17 00:00:00 2001
From: UnCLAS-Prommer
Date: Wed, 23 Apr 2025 22:48:12 +0800
Subject: [PATCH 4/8] 1
---
src/common/logger.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/common/logger.py b/src/common/logger.py
index 740da43b0..017f60fee 100644
--- a/src/common/logger.py
+++ b/src/common/logger.py
@@ -32,8 +32,8 @@ _custom_style_handlers: Dict[Tuple[str, str], List[int]] = {} # 记录自定义
current_file_path = Path(__file__).resolve()
LOG_ROOT = "logs"
-SIMPLE_OUTPUT = os.getenv("SIMPLE_OUTPUT", "false")
-if SIMPLE_OUTPUT == "true" or SIMPLE_OUTPUT == "True":
+SIMPLE_OUTPUT = os.getenv("SIMPLE_OUTPUT", "false").strip().lower()
+if SIMPLE_OUTPUT == "true":
SIMPLE_OUTPUT = True
else:
SIMPLE_OUTPUT = False
From f47d2a8b4f8f6cdfb6652d9c424e68c6a8174b64 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A2=A8=E6=A2=93=E6=9F=92?= <1787882683@qq.com>
Date: Wed, 23 Apr 2025 22:50:17 +0800
Subject: [PATCH 5/8] =?UTF-8?q?refactor(logger):=20=E7=A7=BB=E9=99=A4?=
=?UTF-8?q?=E6=97=A5=E5=BF=97=E6=A0=BC=E5=BC=8F=E4=B8=AD=E7=9A=84=E6=A8=A1?=
=?UTF-8?q?=E5=9D=97=E4=BF=A1=E6=81=AF=E4=BB=A5=E7=AE=80=E5=8C=96=E8=BE=93?=
=?UTF-8?q?=E5=87=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
移除日志格式中的`{extra[module]}`字段,使日志输出更加简洁且易于阅读
---
src/common/logger.py | 63 ++++++++++++++++++++++----------------------
1 file changed, 31 insertions(+), 32 deletions(-)
diff --git a/src/common/logger.py b/src/common/logger.py
index 740da43b0..99e28254e 100644
--- a/src/common/logger.py
+++ b/src/common/logger.py
@@ -75,8 +75,7 @@ MEMORY_STYLE_CONFIG = {
"advanced": {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
- "{extra[module]: <12} | "
+ "{level: <8} | "
"海马体 | "
"{message}"
),
@@ -95,8 +94,8 @@ PFC_STYLE_CONFIG = {
"advanced": {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
- "{extra[module]: <12} | "
+ "{level: <8} | "
+
"PFC | "
"{message}"
),
@@ -115,8 +114,8 @@ MOOD_STYLE_CONFIG = {
"advanced": {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
- "{extra[module]: <12} | "
+ "{level: <8} | "
+
"心情 | "
"{message}"
),
@@ -132,8 +131,8 @@ TOOL_USE_STYLE_CONFIG = {
"advanced": {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
- "{extra[module]: <12} | "
+ "{level: <8} | "
+
"工具使用 | "
"{message}"
),
@@ -151,8 +150,8 @@ RELATION_STYLE_CONFIG = {
"advanced": {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
- "{extra[module]: <12} | "
+ "{level: <8} | "
+
"关系 | "
"{message}"
),
@@ -169,8 +168,8 @@ CONFIG_STYLE_CONFIG = {
"advanced": {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
- "{extra[module]: <12} | "
+ "{level: <8} | "
+
"配置 | "
"{message}"
),
@@ -186,8 +185,8 @@ SENDER_STYLE_CONFIG = {
"advanced": {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
- "{extra[module]: <12} | "
+ "{level: <8} | "
+
"消息发送 | "
"{message}"
),
@@ -203,8 +202,8 @@ HEARTFLOW_STYLE_CONFIG = {
"advanced": {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
- "{extra[module]: <12} | "
+ "{level: <8} | "
+
"麦麦大脑袋 | "
"{message}"
),
@@ -222,8 +221,8 @@ SCHEDULE_STYLE_CONFIG = {
"advanced": {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
- "{extra[module]: <12} | "
+ "{level: <8} | "
+
"在干嘛 | "
"{message}"
),
@@ -239,8 +238,8 @@ LLM_STYLE_CONFIG = {
"advanced": {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
- "{extra[module]: <12} | "
+ "{level: <8} | "
+
"麦麦组织语言 | "
"{message}"
),
@@ -258,8 +257,8 @@ TOPIC_STYLE_CONFIG = {
"advanced": {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
- "{extra[module]: <12} | "
+ "{level: <8} | "
+
"话题 | "
"{message}"
),
@@ -276,8 +275,8 @@ CHAT_STYLE_CONFIG = {
"advanced": {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
- "{extra[module]: <12} | "
+ "{level: <8} | "
+
"见闻 | "
"{message}"
),
@@ -295,8 +294,8 @@ SUB_HEARTFLOW_STYLE_CONFIG = {
"advanced": {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
- "{extra[module]: <12} | "
+ "{level: <8} | "
+
"麦麦小脑袋 | "
"{message}"
),
@@ -314,8 +313,8 @@ WILLING_STYLE_CONFIG = {
"advanced": {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
- "{extra[module]: <12} | "
+ "{level: <8} | "
+
"意愿 | "
"{message}"
),
@@ -332,8 +331,8 @@ MAI_STATE_CONFIG = {
"advanced": {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
- "{extra[module]: <12} | "
+ "{level: <8} | "
+
"麦麦状态 | "
"{message}"
),
@@ -350,8 +349,8 @@ LPMM_STYLE_CONFIG = {
"advanced": {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
- "{level: <8} | "
- "{extra[module]: <12} | "
+ "{level: <8} | "
+
"LPMM | "
"{message}"
),
From 2a424d087c3ec2e98df185d6919ae1011815fa68 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
Date: Wed, 23 Apr 2025 14:50:38 +0000
Subject: [PATCH 6/8] =?UTF-8?q?=F0=9F=A4=96=20=E8=87=AA=E5=8A=A8=E6=A0=BC?=
=?UTF-8?q?=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81=20[skip=20ci]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/common/logger.py | 15 ---------------
1 file changed, 15 deletions(-)
diff --git a/src/common/logger.py b/src/common/logger.py
index e139cc022..b6d690cdb 100644
--- a/src/common/logger.py
+++ b/src/common/logger.py
@@ -95,7 +95,6 @@ PFC_STYLE_CONFIG = {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
"{level: <8} | "
-
"PFC | "
"{message}"
),
@@ -115,7 +114,6 @@ MOOD_STYLE_CONFIG = {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
"{level: <8} | "
-
"心情 | "
"{message}"
),
@@ -132,7 +130,6 @@ TOOL_USE_STYLE_CONFIG = {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
"{level: <8} | "
-
"工具使用 | "
"{message}"
),
@@ -151,7 +148,6 @@ RELATION_STYLE_CONFIG = {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
"{level: <8} | "
-
"关系 | "
"{message}"
),
@@ -169,7 +165,6 @@ CONFIG_STYLE_CONFIG = {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
"{level: <8} | "
-
"配置 | "
"{message}"
),
@@ -186,7 +181,6 @@ SENDER_STYLE_CONFIG = {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
"{level: <8} | "
-
"消息发送 | "
"{message}"
),
@@ -203,7 +197,6 @@ HEARTFLOW_STYLE_CONFIG = {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
"{level: <8} | "
-
"麦麦大脑袋 | "
"{message}"
),
@@ -222,7 +215,6 @@ SCHEDULE_STYLE_CONFIG = {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
"{level: <8} | "
-
"在干嘛 | "
"{message}"
),
@@ -239,7 +231,6 @@ LLM_STYLE_CONFIG = {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
"{level: <8} | "
-
"麦麦组织语言 | "
"{message}"
),
@@ -258,7 +249,6 @@ TOPIC_STYLE_CONFIG = {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
"{level: <8} | "
-
"话题 | "
"{message}"
),
@@ -276,7 +266,6 @@ CHAT_STYLE_CONFIG = {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
"{level: <8} | "
-
"见闻 | "
"{message}"
),
@@ -295,7 +284,6 @@ SUB_HEARTFLOW_STYLE_CONFIG = {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
"{level: <8} | "
-
"麦麦小脑袋 | "
"{message}"
),
@@ -314,7 +302,6 @@ WILLING_STYLE_CONFIG = {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
"{level: <8} | "
-
"意愿 | "
"{message}"
),
@@ -332,7 +319,6 @@ MAI_STATE_CONFIG = {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
"{level: <8} | "
-
"麦麦状态 | "
"{message}"
),
@@ -350,7 +336,6 @@ LPMM_STYLE_CONFIG = {
"console_format": (
"{time:YYYY-MM-DD HH:mm:ss} | "
"{level: <8} | "
-
"LPMM | "
"{message}"
),
From c727929bcfe796dd984f015652b558550ebc72ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=A2=A8=E6=A2=93=E6=9F=92?= <1787882683@qq.com>
Date: Wed, 23 Apr 2025 23:04:30 +0800
Subject: [PATCH 7/8] =?UTF-8?q?refactor(logger):=20=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=E6=97=A5=E5=BF=97=E9=85=8D=E7=BD=AE=E4=BB=A5=E5=A2=9E=E5=BC=BA?=
=?UTF-8?q?=E5=8F=AF=E8=AF=BB=E6=80=A7=E5=92=8C=E4=B8=80=E8=87=B4=E6=80=A7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
重构日志模块,引入MAIN_STYLE_CONFIG和INTEREST_STYLE_CONFIG配置,统一日志格式。通过LogConfig类传递配置参数,确保日志输出在不同模块中保持一致性和可读性。
---
src/common/logger.py | 39 +++++++++++++++++++++++++++++++
src/heart_flow/interest_logger.py | 8 +++++--
src/main.py | 8 +++++--
3 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/src/common/logger.py b/src/common/logger.py
index e139cc022..7818ae155 100644
--- a/src/common/logger.py
+++ b/src/common/logger.py
@@ -70,6 +70,24 @@ else:
}
+MAIN_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}",
+ },
+}
+
# 海马体日志样式配置
MEMORY_STYLE_CONFIG = {
"advanced": {
@@ -364,12 +382,32 @@ LPMM_STYLE_CONFIG = {
},
}
+# 兴趣log
+INTEREST_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}",
+ },
+}
+
CONFIRM_STYLE_CONFIG = {
"console_format": "{message}", # noqa: E501
"file_format": "{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {extra[module]: <15} | EULA与PRIVACY确认 | {message}",
}
# 根据SIMPLE_OUTPUT选择配置
+MAIN_STYLE_CONFIG = MAIN_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else MAIN_STYLE_CONFIG["advanced"]
MEMORY_STYLE_CONFIG = MEMORY_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else MEMORY_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"]
@@ -388,6 +426,7 @@ CONFIG_STYLE_CONFIG = CONFIG_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else CONFIG
TOOL_USE_STYLE_CONFIG = TOOL_USE_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else TOOL_USE_STYLE_CONFIG["advanced"]
PFC_STYLE_CONFIG = PFC_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else PFC_STYLE_CONFIG["advanced"]
LPMM_STYLE_CONFIG = LPMM_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else LPMM_STYLE_CONFIG["advanced"]
+INTEREST_STYLE_CONFIG = INTEREST_STYLE_CONFIG["simple"] if SIMPLE_OUTPUT else INTEREST_STYLE_CONFIG["advanced"]
def is_registered_module(record: dict) -> bool:
diff --git a/src/heart_flow/interest_logger.py b/src/heart_flow/interest_logger.py
index 3833ef881..206cfa4bf 100644
--- a/src/heart_flow/interest_logger.py
+++ b/src/heart_flow/interest_logger.py
@@ -5,7 +5,7 @@ import os
import traceback
from typing import TYPE_CHECKING, Dict, List
-from src.common.logger import get_module_logger
+from src.common.logger import get_module_logger, LogConfig, INTEREST_STYLE_CONFIG
# Need chat_manager to get stream names
from src.plugins.chat.chat_stream import chat_manager
@@ -14,7 +14,11 @@ if TYPE_CHECKING:
from src.heart_flow.subheartflow_manager import SubHeartflowManager
from src.heart_flow.sub_heartflow import SubHeartflow # For type hint in get_interest_states
-logger = get_module_logger("interest_logger")
+interest_logger_config = LogConfig(
+ console_format = INTEREST_STYLE_CONFIG["console_format"],
+ file_format=INTEREST_STYLE_CONFIG["file_format"],
+)
+logger = get_module_logger("interest_logger", config=interest_logger_config)
# Consider moving log directory/filename constants here
LOG_DIRECTORY = "logs/interest"
diff --git a/src/main.py b/src/main.py
index 75ab2ae72..62fa70a6e 100644
--- a/src/main.py
+++ b/src/main.py
@@ -13,12 +13,16 @@ from .plugins.chat.message_sender import message_manager
from .plugins.storage.storage import MessageStorage
from .config.config import global_config
from .plugins.chat.bot import chat_bot
-from .common.logger import get_module_logger
+from .common.logger import get_module_logger, LogConfig, MAIN_STYLE_CONFIG
from .plugins.remote import heartbeat_thread # noqa: F401
from .individuality.individuality import Individuality
from .common.server import global_server
-logger = get_module_logger("main")
+main_log_config = LogConfig(
+ console_format=MAIN_STYLE_CONFIG["console_format"],
+ file_format=MAIN_STYLE_CONFIG["file_format"],
+)
+logger = get_module_logger("main", config=main_log_config)
class MainSystem:
From b4f37d04fec63aad7ec4fa2560d3ef89ce9cd572 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
Date: Wed, 23 Apr 2025 15:04:54 +0000
Subject: [PATCH 8/8] =?UTF-8?q?=F0=9F=A4=96=20=E8=87=AA=E5=8A=A8=E6=A0=BC?=
=?UTF-8?q?=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81=20[skip=20ci]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/heart_flow/interest_logger.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/heart_flow/interest_logger.py b/src/heart_flow/interest_logger.py
index 206cfa4bf..4b7e6323e 100644
--- a/src/heart_flow/interest_logger.py
+++ b/src/heart_flow/interest_logger.py
@@ -15,7 +15,7 @@ if TYPE_CHECKING:
from src.heart_flow.sub_heartflow import SubHeartflow # For type hint in get_interest_states
interest_logger_config = LogConfig(
- console_format = INTEREST_STYLE_CONFIG["console_format"],
+ console_format=INTEREST_STYLE_CONFIG["console_format"],
file_format=INTEREST_STYLE_CONFIG["file_format"],
)
logger = get_module_logger("interest_logger", config=interest_logger_config)