diff --git a/plugin_common/plugin_manager.py b/plugin_common/plugin_manager.py index f408520..1eef48d 100644 --- a/plugin_common/plugin_manager.py +++ b/plugin_common/plugin_manager.py @@ -63,7 +63,7 @@ class PluginManager: elif item.endswith(".py") and not item.startswith("__"): # 单文件插件 plugin_modules.append(item[:-3]) - self.LOG.info(f"发现插件模块: {plugin_modules}") + self.LOG.info(f"PluginManager:发现插件模块: {plugin_modules}") return plugin_modules def load_all_plugins(self) -> Dict[str, PluginInterface]: @@ -81,9 +81,9 @@ class PluginManager: if self.load_plugin(plugin_name): loaded_plugins.append(plugin_name) except Exception as e: - self.LOG.error(f"加载插件 {plugin_name} 时发生错误: {str(e)}", exc_info=True) + self.LOG.error(f"PluginManager:加载插件 {plugin_name} 时发生错误: {str(e)}", exc_info=True) - self.LOG.info(f"成功加载插件: {loaded_plugins}") + self.LOG.info(f"PluginManager:成功加载插件: {loaded_plugins}") return self.plugins def load_plugin(self, plugin_name: str) -> Optional[PluginInterface]: @@ -112,7 +112,7 @@ class PluginManager: module = importlib.import_module(module_path) self.plugin_modules[plugin_name] = module except ImportError as e: - self.LOG.error(f"导入插件模块 {module_path} 失败: {e}") + self.LOG.error(f"PluginManager:导入插件模块 {module_path} 失败: {e}") return None else: # 单文件插件 @@ -121,7 +121,7 @@ class PluginManager: module = importlib.import_module(plugin_name) self.plugin_modules[plugin_name] = module except ImportError as e: - self.LOG.error(f"导入单文件插件 {plugin_name} 失败: {e}") + self.LOG.error(f"PluginManager:导入单文件插件 {plugin_name} 失败: {e}") return None # 查找插件类 @@ -146,12 +146,12 @@ class PluginManager: # 加载插件配置 if not plugin.load_config(): - self.LOG.error(f"插件 {plugin_name} 加载配置失败") + self.LOG.error(f"PluginManager:插件 {plugin_name} 加载配置失败") return None # 初始化插件 if not plugin.initialize(self.system_context): - self.LOG.error(f"插件 {plugin_name} 初始化失败") + self.LOG.error(f"PluginManager:插件 {plugin_name} 初始化失败") return None # 注册插件 @@ -165,9 +165,9 @@ class PluginManager: return plugin else: - self.LOG.error(f"插件 {plugin_name} 的 get_plugin() 返回的不是有效的插件实例") + self.LOG.error(f"PluginManager:插件 {plugin_name} 的 get_plugin() 返回的不是有效的插件实例") else: - self.LOG.error(f"插件 {plugin_name} 中未找到有效的插件类或 get_plugin 函数") + self.LOG.error(f"PluginManager:插件 {plugin_name} 中未找到有效的插件类或 get_plugin 函数") return None # 实例化插件 @@ -179,12 +179,12 @@ class PluginManager: # 加载插件配置 if not plugin.load_config(): - self.LOG.error(f"插件 {plugin_name} 加载配置失败") + self.LOG.error(f"PluginManager:插件 {plugin_name} 加载配置失败") return None # 初始化插件 if not plugin.initialize(self.system_context): - self.LOG.error(f"插件 {plugin_name} 初始化失败") + self.LOG.error(f"PluginManager:插件 {plugin_name} 初始化失败") return None # 注册插件 @@ -199,7 +199,7 @@ class PluginManager: return plugin except Exception as e: - self.LOG.error(f"加载插件 {plugin_name} 失败: {e}", exc_info=True) + self.LOG.error(f"PluginManager:加载插件 {plugin_name} 失败: {e}", exc_info=True) return None def unload_plugin(self, plugin_name: str) -> bool: @@ -213,7 +213,7 @@ class PluginManager: 卸载是否成功 """ if plugin_name not in self.plugins: - self.LOG.info(f"插件 {plugin_name} 未加载") + self.LOG.info(f"PluginManager:插件 {plugin_name} 未加载") return False plugin = self.plugins[plugin_name] @@ -221,12 +221,12 @@ class PluginManager: # 停止插件 if plugin.status == PluginStatus.RUNNING: if not plugin.stop(): - self.LOG.info(f"停止插件 {plugin_name} 失败") + self.LOG.info(f"PluginManager:停止插件 {plugin_name} 失败") return False # 清理插件资源 if not plugin.cleanup(): - self.LOG.info(f"清理插件 {plugin_name} 资源失败") + self.LOG.info(f"PluginManager:清理插件 {plugin_name} 资源失败") return False # 注销插件 @@ -251,20 +251,22 @@ class PluginManager: 启动是否成功 """ if plugin_name not in self.plugins: - self.LOG.info(f"插件 {plugin_name} 未加载") + self.LOG.info(f"PluginManager:插件 {plugin_name} 未加载") return False plugin = self.plugins[plugin_name] if plugin.status == PluginStatus.RUNNING: - self.LOG.info(f"插件 {plugin_name} 已经在运行") + self.LOG.info(f"PluginManager:插件 {plugin_name} 已经在运行") return True if plugin.start(): plugin.status = PluginStatus.RUNNING + self.LOG.info(f"PluginManager:插件 {plugin_name} 状态变更为在运行") return True else: plugin.status = PluginStatus.ERROR + self.LOG.info(f"PluginManager:插件 {plugin_name} 状态变更为异常") return False def stop_plugin(self, plugin_name: str) -> bool: @@ -289,9 +291,11 @@ class PluginManager: if plugin.stop(): plugin.status = PluginStatus.STOPPED + self.LOG.info(f"插件 {plugin_name} 状态变更为已停止") return True else: plugin.status = PluginStatus.ERROR + self.LOG.info(f"插件 {plugin_name} 状态变更为异常") return False def reload_plugin(self, plugin_name: str) -> Optional[PluginInterface]: