优化日志级别,生产环境中INFO避免打印过多日志

This commit is contained in:
Chingfeng Li
2025-11-11 18:52:14 +08:00
parent cbb74170ea
commit 833f379aa1
10 changed files with 46 additions and 46 deletions
@@ -106,14 +106,14 @@ async def send_mcp_message(conn, payload: dict):
try:
await conn.websocket.send(message)
logger.bind(tag=TAG).info(f"成功发送MCP消息: {message}")
logger.bind(tag=TAG).debug(f"成功发送MCP消息: {message}")
except Exception as e:
logger.bind(tag=TAG).error(f"发送MCP消息失败: {e}")
async def handle_mcp_message(conn, mcp_client: MCPClient, payload: dict):
"""处理MCP消息,包括初始化、工具列表和工具调用响应等"""
logger.bind(tag=TAG).info(f"处理MCP消息: {str(payload)[:100]}")
logger.bind(tag=TAG).debug(f"处理MCP消息: {str(payload)[:100]}")
if not isinstance(payload, dict):
logger.bind(tag=TAG).error("MCP消息缺少payload字段或格式错误")
@@ -138,7 +138,7 @@ async def handle_mcp_message(conn, mcp_client: MCPClient, payload: dict):
if isinstance(server_info, dict):
name = server_info.get("name")
version = server_info.get("version")
logger.bind(tag=TAG).info(
logger.bind(tag=TAG).debug(
f"客户端MCP服务器信息: name={name}, version={version}"
)
return
@@ -195,11 +195,11 @@ async def handle_mcp_message(conn, mcp_client: MCPClient, payload: dict):
next_cursor = result.get("nextCursor", "")
if next_cursor:
logger.bind(tag=TAG).info(f"有更多工具,nextCursor: {next_cursor}")
logger.bind(tag=TAG).debug(f"有更多工具,nextCursor: {next_cursor}")
await send_mcp_tools_list_continue_request(conn, next_cursor)
else:
await mcp_client.set_ready(True)
logger.bind(tag=TAG).info("所有工具已获取,MCP客户端准备就绪")
logger.bind(tag=TAG).debug("所有工具已获取,MCP客户端准备就绪")
# 刷新工具缓存,确保MCP工具被包含在函数列表中
if hasattr(conn, "func_handler") and conn.func_handler:
@@ -255,7 +255,7 @@ async def send_mcp_initialize_message(conn):
},
},
}
logger.bind(tag=TAG).info("发送MCP初始化消息")
logger.bind(tag=TAG).debug("发送MCP初始化消息")
await send_mcp_message(conn, payload)
@@ -69,7 +69,7 @@ class UnifiedToolHandler:
self._initialize_home_assistant()
self.finish_init = True
self.logger.info("统一工具处理器初始化完成")
self.logger.debug("统一工具处理器初始化完成")
# 输出当前支持的所有工具列表
self.current_support_functions()
@@ -20,7 +20,7 @@ class ToolManager:
"""注册工具执行器"""
self.executors[tool_type] = executor
self._invalidate_cache()
self.logger.info(f"注册工具执行器: {tool_type.value}")
self.logger.debug(f"注册工具执行器: {tool_type.value}")
def _invalidate_cache(self):
"""使缓存失效"""
@@ -109,7 +109,7 @@ class ToolManager:
def refresh_tools(self):
"""刷新工具缓存"""
self._invalidate_cache()
self.logger.info("工具缓存已刷新")
self.logger.debug("工具缓存已刷新")
def get_tool_statistics(self) -> Dict[str, int]:
"""获取工具统计信息"""