From 508f30b7ec4eac1b4b46af866c6fd19442e1e35d Mon Sep 17 00:00:00 2001 From: liuwei Date: Wed, 19 Mar 2025 14:08:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=87=E4=BB=A4=E9=83=BD=E6=98=AF=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC=E4=B9=8B=E5=89=8D=E5=86=85=E5=AE=B9=EF=BC=8C=E4=BD=9C?= =?UTF-8?q?=E4=B8=BA=E6=A0=87=E5=87=86=E5=8C=96=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/stats_collector/decorators.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/stats_collector/decorators.py b/plugins/stats_collector/decorators.py index 83333d2..1eb1788 100644 --- a/plugins/stats_collector/decorators.py +++ b/plugins/stats_collector/decorators.py @@ -38,7 +38,10 @@ def plugin_stats_decorator(plugin_name: str) -> Callable: sender = message.get("sender", "") roomid = message.get("roomid", "") - logger.debug(f"[{plugin_name}] 消息内容: '{content}', 发送者: {sender}, 群ID: {roomid}") + # 提取指令部分(假设指令是第一个单词或空格前的部分) + command = content.strip().split(' ')[0] if content else "" + + logger.debug(f"[{plugin_name}] 消息内容: '{content}', 指令: '{command}', 发送者: {sender}, 群ID: {roomid}") # 记录开始时间 start_time = time.time() @@ -58,13 +61,13 @@ def plugin_stats_decorator(plugin_name: str) -> Callable: logger.debug(f"[{plugin_name}] 记录插件调用统计") stats_db.record_plugin_call( plugin_name=plugin_name, - command=content, + command=command, # 使用提取的指令而不是完整内容 user_id=sender, group_id=roomid, success=success, process_time_ms=process_time_ms ) - logger.info(f"[{plugin_name}] 成功记录插件调用: {content}, 耗时: {process_time_ms:.2f}ms") + logger.info(f"[{plugin_name}] 成功记录插件调用: {command}, 耗时: {process_time_ms:.2f}ms") return success, response except Exception as e: @@ -83,7 +86,7 @@ def plugin_stats_decorator(plugin_name: str) -> Callable: logger.debug(f"[{plugin_name}] 记录插件调用失败统计") stats_db.record_plugin_call( plugin_name=plugin_name, - command=content, + command=command, # 使用提取的指令而不是完整内容 user_id=sender, group_id=roomid, success=False, @@ -94,13 +97,13 @@ def plugin_stats_decorator(plugin_name: str) -> Callable: logger.debug(f"[{plugin_name}] 记录错误详情") stats_db.record_error( plugin_name=plugin_name, - command=content, + command=command, # 使用提取的指令而不是完整内容 user_id=sender, group_id=roomid, error_message=error_message, stack_trace=stack_trace ) - logger.info(f"[{plugin_name}] 成功记录插件错误: {content}, 错误: {error_message}") + logger.info(f"[{plugin_name}] 成功记录插件错误: {command}, 错误: {error_message}") except Exception as db_error: logger.error(f"[{plugin_name}] 记录插件统计数据失败: {db_error}")