855 协议版本-调整完毕内容
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import logging
|
||||
from loguru import logger
|
||||
import time
|
||||
from typing import Dict, Any, Tuple, Optional, List
|
||||
from datetime import datetime
|
||||
@@ -42,7 +42,7 @@ class StatsCollectorPlugin(PluginInterface):
|
||||
def __init__(self):
|
||||
|
||||
super().__init__()
|
||||
self.logger = logging.getLogger("StatsCollector")
|
||||
self.LOG = logger
|
||||
|
||||
self.LOG.info(f"正在初始化 {self.name} 插件...")
|
||||
# 默认配置
|
||||
@@ -62,7 +62,7 @@ class StatsCollectorPlugin(PluginInterface):
|
||||
self.config.update(config)
|
||||
|
||||
if not self.config["enable"]:
|
||||
self.logger.info("统计收集插件已禁用")
|
||||
self.LOG.info("统计收集插件已禁用")
|
||||
return False
|
||||
|
||||
# 注册事件处理器
|
||||
@@ -79,7 +79,7 @@ class StatsCollectorPlugin(PluginInterface):
|
||||
return
|
||||
|
||||
# 记录开始时间和相关信息
|
||||
self.logger.debug(f"记录插件调用开始: {event.plugin_name} - {event.command}")
|
||||
self.LOG.debug(f"记录插件调用开始: {event.plugin_name} - {event.command}")
|
||||
|
||||
def handle_plugin_call_end(self, event: PluginCallEndEvent) -> None:
|
||||
"""处理插件调用结束事件"""
|
||||
@@ -98,10 +98,10 @@ class StatsCollectorPlugin(PluginInterface):
|
||||
success=event.process_result,
|
||||
process_time_ms=event.process_time
|
||||
)
|
||||
self.logger.debug(
|
||||
self.LOG.debug(
|
||||
f"记录插件调用结束: {event.plugin_name} - {event.command} - 成功: {event.process_result} - 处理时间: {event.process_time}ms")
|
||||
except Exception as e:
|
||||
self.logger.error(f"记录插件调用统计数据出错: {e}")
|
||||
self.LOG.error(f"记录插件调用统计数据出错: {e}")
|
||||
|
||||
def handle_plugin_error(self, event: PluginCallErrorEvent) -> None:
|
||||
"""处理插件调用错误事件"""
|
||||
@@ -119,9 +119,9 @@ class StatsCollectorPlugin(PluginInterface):
|
||||
error_message=event.error_message,
|
||||
stack_trace=event.stack_trace
|
||||
)
|
||||
self.logger.debug(f"记录插件调用错误: {event.plugin_name} - {event.command} - {event.error_message}")
|
||||
self.LOG.debug(f"记录插件调用错误: {event.plugin_name} - {event.command} - {event.error_message}")
|
||||
except Exception as e:
|
||||
self.logger.error(f"记录插件错误信息出错: {e}")
|
||||
self.LOG.error(f"记录插件错误信息出错: {e}")
|
||||
|
||||
def _should_record_plugin(self, plugin_name: str) -> bool:
|
||||
"""检查是否应该记录该插件的调用"""
|
||||
@@ -154,7 +154,7 @@ class StatsCollectorPlugin(PluginInterface):
|
||||
self.event_manager.unregister(PluginCallEndEvent, self.handle_plugin_call_end)
|
||||
self.event_manager.unregister(PluginCallErrorEvent, self.handle_plugin_error)
|
||||
|
||||
self.logger.info("统计收集插件已关闭")
|
||||
self.LOG.info("统计收集插件已关闭")
|
||||
|
||||
def start(self) -> bool:
|
||||
"""启动插件"""
|
||||
|
||||
Reference in New Issue
Block a user