feat: localize ai log tags to Chinese in console formatter

This commit is contained in:
2026-03-01 17:30:01 +08:00
parent 219a265a5e
commit 3972764c79

View File

@@ -31,6 +31,15 @@ def _get_transfer_group(acc_id: str) -> str:
# ========== 日志配置(轮转:按大小 10MB保留 7 份)========== # ========== 日志配置(轮转:按大小 10MB保留 7 份)==========
class _AnsiColorFormatter(logging.Formatter): class _AnsiColorFormatter(logging.Formatter):
RESET = "\033[0m" RESET = "\033[0m"
MESSAGE_TEXT_REPLACEMENTS = (
("[PROMPT->AI 前置提示词]", "[AI提示词]"),
("[PROMPT->AI", "[AI提示词"),
("[THINK/TOOL_CALL]", "[AI思考-工具调用]"),
("[THINK/TOOL_RETURN]", "[AI思考-工具返回]"),
("[THINK/RAW_OUTPUT]", "[AI思考-原始输出]"),
("[REPLY->CUSTOMER]", "[AI回复客户]"),
("[ACTIVITY]", "[活动日志]"),
)
# 业务消息类型颜色(优先于 level # 业务消息类型颜色(优先于 level
MESSAGE_COLOR_RULES = ( MESSAGE_COLOR_RULES = (
("[PROMPT->AI", "\033[94m"), # bright blue ("[PROMPT->AI", "\033[94m"), # bright blue
@@ -57,8 +66,12 @@ class _AnsiColorFormatter(logging.Formatter):
def format(self, record: logging.LogRecord) -> str: def format(self, record: logging.LogRecord) -> str:
msg = super().format(record) msg = super().format(record)
if not self.use_color: if not self.use_color:
for old, new in self.MESSAGE_TEXT_REPLACEMENTS:
msg = msg.replace(old, new)
return msg return msg
raw_msg = record.getMessage() raw_msg = record.getMessage()
for old, new in self.MESSAGE_TEXT_REPLACEMENTS:
msg = msg.replace(old, new)
for key, color in self.MESSAGE_COLOR_RULES: for key, color in self.MESSAGE_COLOR_RULES:
if key in raw_msg: if key in raw_msg:
return f"{color}{msg}{self.RESET}" return f"{color}{msg}{self.RESET}"