优化日志

This commit is contained in:
Windpicker-owo
2025-11-26 21:16:16 +08:00
parent e0157256b1
commit 0908fb50a0
100 changed files with 493 additions and 574 deletions

View File

@@ -513,7 +513,7 @@ class BaseAction(ABC):
return result
except Exception as e:
logger.error(f"{log_prefix} 调用时发生错误: {e}", exc_info=True)
logger.error(f"{log_prefix} 调用时发生错误: {e}")
return False, f"调用Action '{action_name}' 时发生错误: {e}"
@classmethod

View File

@@ -179,7 +179,7 @@ class BaseAdapter(MoFoxAdapterBase, ABC):
except asyncio.CancelledError:
break
except Exception as e:
logger.error(f"适配器 {self.adapter_name} 健康检查异常: {e}", exc_info=True)
logger.error(f"适配器 {self.adapter_name} 健康检查异常: {e}")
async def health_check(self) -> bool:
"""
@@ -204,7 +204,7 @@ class BaseAdapter(MoFoxAdapterBase, ABC):
await asyncio.sleep(2) # 等待一段时间再重连
await self.start()
except Exception as e:
logger.error(f"适配器 {self.adapter_name} 重连失败: {e}", exc_info=True)
logger.error(f"适配器 {self.adapter_name} 重连失败: {e}")
def get_subprocess_entry_path(self) -> Optional[Path]:
"""

View File

@@ -141,7 +141,7 @@ class PluginBase(ABC):
f.write(toml_str)
logger.info(f"{self.log_prefix} 已生成默认配置文件: {config_file_path}")
except OSError as e:
logger.error(f"{self.log_prefix} 保存默认配置文件失败: {e}", exc_info=True)
logger.error(f"{self.log_prefix} 保存默认配置文件失败: {e}")
def _backup_config_file(self, config_file_path: str) -> str:
"""备份配置文件到指定的 backup 子目录"""
@@ -158,7 +158,7 @@ class PluginBase(ABC):
logger.info(f"{self.log_prefix} 配置文件已备份到: {backup_path}")
return str(backup_path)
except Exception as e:
logger.error(f"{self.log_prefix} 备份配置文件失败: {e}", exc_info=True)
logger.error(f"{self.log_prefix} 备份配置文件失败: {e}")
return ""
def _synchronize_config(
@@ -285,7 +285,7 @@ class PluginBase(ABC):
f.write(toml_str)
logger.info(f"{self.log_prefix} 配置文件已保存: {config_file_path}")
except OSError as e:
logger.error(f"{self.log_prefix} 保存配置文件失败: {e}", exc_info=True)
logger.error(f"{self.log_prefix} 保存配置文件失败: {e}")
def _load_plugin_config(self): # sourcery skip: extract-method
"""
@@ -314,7 +314,7 @@ class PluginBase(ABC):
shutil.move(plugin_config_path, user_config_path)
logger.info(f"{self.log_prefix} 已将配置文件从 {plugin_config_path} 迁移到 {user_config_path}")
except OSError as e:
logger.error(f"{self.log_prefix} 迁移配置文件失败: {e}", exc_info=True)
logger.error(f"{self.log_prefix} 迁移配置文件失败: {e}")
# 如果用户配置文件仍然不存在,生成默认的
if not os.path.exists(user_config_path):
@@ -333,7 +333,7 @@ class PluginBase(ABC):
with open(user_config_path, encoding="utf-8") as f:
user_config: dict[str, Any] = toml.load(f) or {}
except Exception as e:
logger.error(f"{self.log_prefix} 加载用户配置文件 {user_config_path} 失败: {e}", exc_info=True)
logger.error(f"{self.log_prefix} 加载用户配置文件 {user_config_path} 失败: {e}")
self.config = self._generate_config_from_schema() # 加载失败时使用默认 schema
return

View File

@@ -384,7 +384,7 @@ def create_plus_command_adapter(plus_command_class):
try:
return await self.plus_command.execute(command_args)
except Exception as e:
logger.error(f"执行命令时出错: {e}", exc_info=True)
logger.error(f"执行命令时出错: {e}")
return False, f"命令执行出错: {e!s}", self.intercept_message
return AdapterClass
@@ -443,7 +443,7 @@ def create_legacy_command_adapter(legacy_command_class):
# 旧的execute不接收args参数
return await self.legacy_command.execute()
except Exception as e:
logger.error(f"执行旧版命令 '{self.command_name}' 时出错: {e}", exc_info=True)
logger.error(f"执行旧版命令 '{self.command_name}' 时出错: {e}")
return False, f"命令执行出错: {e!s}", self.intercept_message
return LegacyAdapter