feat: localize ai log tags to Chinese in console formatter
This commit is contained in:
@@ -31,6 +31,15 @@ def _get_transfer_group(acc_id: str) -> str:
|
||||
# ========== 日志配置(轮转:按大小 10MB,保留 7 份)==========
|
||||
class _AnsiColorFormatter(logging.Formatter):
|
||||
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)
|
||||
MESSAGE_COLOR_RULES = (
|
||||
("[PROMPT->AI", "\033[94m"), # bright blue
|
||||
@@ -57,8 +66,12 @@ class _AnsiColorFormatter(logging.Formatter):
|
||||
def format(self, record: logging.LogRecord) -> str:
|
||||
msg = super().format(record)
|
||||
if not self.use_color:
|
||||
for old, new in self.MESSAGE_TEXT_REPLACEMENTS:
|
||||
msg = msg.replace(old, new)
|
||||
return msg
|
||||
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:
|
||||
if key in raw_msg:
|
||||
return f"{color}{msg}{self.RESET}"
|
||||
|
||||
Reference in New Issue
Block a user