调整日志
This commit is contained in:
@@ -90,7 +90,7 @@ class PluginManager:
|
|||||||
elif item.endswith(".py") and not item.startswith("__"):
|
elif item.endswith(".py") and not item.startswith("__"):
|
||||||
# 单文件插件
|
# 单文件插件
|
||||||
module_names.append(item[:-3])
|
module_names.append(item[:-3])
|
||||||
self.LOG.info(f"PluginManager:发现插件模块: {module_names}")
|
self.LOG.debug(f"PluginManager:发现插件模块: {module_names}")
|
||||||
return module_names
|
return module_names
|
||||||
|
|
||||||
def load_all_plugins(self) -> Dict[str, PluginInterface]:
|
def load_all_plugins(self) -> Dict[str, PluginInterface]:
|
||||||
@@ -105,7 +105,7 @@ class PluginManager:
|
|||||||
failed_modules = []
|
failed_modules = []
|
||||||
|
|
||||||
# 记录开始加载的插件列表
|
# 记录开始加载的插件列表
|
||||||
self.LOG.info(f"PluginManager:开始加载插件列表: {module_names}")
|
self.LOG.debug(f"PluginManager:开始加载插件列表: {module_names}")
|
||||||
|
|
||||||
for module_name in module_names:
|
for module_name in module_names:
|
||||||
try:
|
try:
|
||||||
@@ -127,14 +127,14 @@ class PluginManager:
|
|||||||
module_name = self._get_module_name_from_plugin(plugin)
|
module_name = self._get_module_name_from_plugin(plugin)
|
||||||
if module_name and module_name not in self.module_to_display:
|
if module_name and module_name not in self.module_to_display:
|
||||||
self.module_to_display[module_name] = display_name
|
self.module_to_display[module_name] = display_name
|
||||||
self.LOG.info(f"PluginManager:补充缺失的模块映射 {module_name} -> {display_name}")
|
self.LOG.debug(f"PluginManager:补充缺失的模块映射 {module_name} -> {display_name}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.LOG.warning(f"PluginManager:获取插件 {display_name} 的模块名时出错: {e}")
|
self.LOG.warning(f"PluginManager:获取插件 {display_name} 的模块名时出错: {e}")
|
||||||
# 使用插件显示名称作为备选模块名
|
# 使用插件显示名称作为备选模块名
|
||||||
folder_name = display_name.lower().replace(' ', '_')
|
folder_name = display_name.lower().replace(' ', '_')
|
||||||
if folder_name not in self.module_to_display:
|
if folder_name not in self.module_to_display:
|
||||||
self.module_to_display[folder_name] = display_name
|
self.module_to_display[folder_name] = display_name
|
||||||
self.LOG.info(f"PluginManager:使用目录名作为模块映射 {folder_name} -> {display_name}")
|
self.LOG.debug(f"PluginManager:使用目录名作为模块映射 {folder_name} -> {display_name}")
|
||||||
|
|
||||||
# 检查是否有重复或无效的映射
|
# 检查是否有重复或无效的映射
|
||||||
invalid_mappings = []
|
invalid_mappings = []
|
||||||
@@ -146,14 +146,14 @@ class PluginManager:
|
|||||||
# 清理无效的映射
|
# 清理无效的映射
|
||||||
for module_name in invalid_mappings:
|
for module_name in invalid_mappings:
|
||||||
del self.module_to_display[module_name]
|
del self.module_to_display[module_name]
|
||||||
self.LOG.info(f"PluginManager:清理无效的模块映射 {module_name}")
|
self.LOG.debug(f"PluginManager:清理无效的模块映射 {module_name}")
|
||||||
|
|
||||||
# 记录最终状态
|
# 记录最终状态
|
||||||
self.LOG.info(f"PluginManager:加载成功的插件模块: {loaded_modules}")
|
self.LOG.debug(f"PluginManager:加载成功的插件模块: {loaded_modules}")
|
||||||
if failed_modules:
|
if failed_modules:
|
||||||
self.LOG.warning(f"PluginManager:加载失败的插件模块: {failed_modules}")
|
self.LOG.warning(f"PluginManager:加载失败的插件模块: {failed_modules}")
|
||||||
self.LOG.info(f"PluginManager:当前已加载的插件实例: {list(self.plugins.keys())}")
|
self.LOG.debug(f"PluginManager:当前已加载的插件实例: {list(self.plugins.keys())}")
|
||||||
self.LOG.info(f"PluginManager:最终的模块映射关系: {self.module_to_display}")
|
self.LOG.debug(f"PluginManager:最终的模块映射关系: {self.module_to_display}")
|
||||||
|
|
||||||
return self.plugins
|
return self.plugins
|
||||||
|
|
||||||
@@ -202,11 +202,11 @@ class PluginManager:
|
|||||||
try:
|
try:
|
||||||
plugin_module_name = self._get_module_name_from_plugin(plugin)
|
plugin_module_name = self._get_module_name_from_plugin(plugin)
|
||||||
if plugin_module_name == module_name:
|
if plugin_module_name == module_name:
|
||||||
self.LOG.info(f"PluginManager:插件模块 {module_name} 已加载为 {display_name}")
|
self.LOG.debug(f"PluginManager:插件模块 {module_name} 已加载为 {display_name}")
|
||||||
# 确保模块名到显示名的映射存在
|
# 确保模块名到显示名的映射存在
|
||||||
if module_name not in self.module_to_display:
|
if module_name not in self.module_to_display:
|
||||||
self.module_to_display[module_name] = display_name
|
self.module_to_display[module_name] = display_name
|
||||||
self.LOG.info(f"PluginManager:添加缺失的模块映射 {module_name} -> {display_name}")
|
self.LOG.debug(f"PluginManager:添加缺失的模块映射 {module_name} -> {display_name}")
|
||||||
return plugin
|
return plugin
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.LOG.warning(f"获取插件 {display_name} 的模块名时出错: {e}")
|
self.LOG.warning(f"获取插件 {display_name} 的模块名时出错: {e}")
|
||||||
@@ -348,19 +348,19 @@ class PluginManager:
|
|||||||
display_name, plugin = self.find_plugin_by_name(name)
|
display_name, plugin = self.find_plugin_by_name(name)
|
||||||
|
|
||||||
if not plugin:
|
if not plugin:
|
||||||
self.LOG.info(f"PluginManager:插件 {name} 未加载")
|
self.LOG.debug(f"PluginManager:插件 {name} 未加载")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# 停止插件
|
# 停止插件
|
||||||
if plugin.status == PluginStatus.RUNNING:
|
if plugin.status == PluginStatus.RUNNING:
|
||||||
if not plugin.stop():
|
if not plugin.stop():
|
||||||
self.LOG.info(f"PluginManager:停止插件 {display_name} 失败")
|
self.LOG.debug(f"PluginManager:停止插件 {display_name} 失败")
|
||||||
return False
|
return False
|
||||||
plugin.status = PluginStatus.STOPPED # 确保状态更新
|
plugin.status = PluginStatus.STOPPED # 确保状态更新
|
||||||
|
|
||||||
# 清理插件资源
|
# 清理插件资源
|
||||||
if not plugin.cleanup():
|
if not plugin.cleanup():
|
||||||
self.LOG.info(f"PluginManager:清理插件 {display_name} 资源失败")
|
self.LOG.debug(f"PluginManager:清理插件 {display_name} 资源失败")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# 设置状态为未加载
|
# 设置状态为未加载
|
||||||
@@ -373,7 +373,7 @@ class PluginManager:
|
|||||||
module_name = self._get_module_name_from_plugin(plugin)
|
module_name = self._get_module_name_from_plugin(plugin)
|
||||||
if module_name and module_name in self.module_to_display:
|
if module_name and module_name in self.module_to_display:
|
||||||
del self.module_to_display[module_name]
|
del self.module_to_display[module_name]
|
||||||
self.LOG.info(f"PluginManager:清理模块映射 {module_name} -> {display_name}")
|
self.LOG.debug(f"PluginManager:清理模块映射 {module_name} -> {display_name}")
|
||||||
|
|
||||||
# 移除插件实例
|
# 移除插件实例
|
||||||
del self.plugins[display_name]
|
del self.plugins[display_name]
|
||||||
@@ -397,7 +397,7 @@ class PluginManager:
|
|||||||
display_name, plugin = self.find_plugin_by_name(name)
|
display_name, plugin = self.find_plugin_by_name(name)
|
||||||
|
|
||||||
if not plugin:
|
if not plugin:
|
||||||
self.LOG.info(f"PluginManager:插件 {name} 未加载,无法重载")
|
self.LOG.debug(f"PluginManager:插件 {name} 未加载,无法重载")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# 记录原插件状态和模块名
|
# 记录原插件状态和模块名
|
||||||
@@ -410,7 +410,7 @@ class PluginManager:
|
|||||||
|
|
||||||
# 卸载插件
|
# 卸载插件
|
||||||
if not self.unload_plugin(display_name):
|
if not self.unload_plugin(display_name):
|
||||||
self.LOG.info(f"卸载插件 {display_name} 失败,无法重载")
|
self.LOG.debug(f"卸载插件 {display_name} 失败,无法重载")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# 重新导入模块
|
# 重新导入模块
|
||||||
@@ -418,7 +418,7 @@ class PluginManager:
|
|||||||
try:
|
try:
|
||||||
importlib.reload(self.plugin_modules[module_name])
|
importlib.reload(self.plugin_modules[module_name])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.LOG.info(f"重新导入插件模块 {module_name} 失败: {e}")
|
self.LOG.debug(f"重新导入插件模块 {module_name} 失败: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# 加载插件
|
# 加载插件
|
||||||
|
|||||||
Reference in New Issue
Block a user