From 9086c15f2e171958037a3fd3ff8fd6dd849a789d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=87=E8=96=87=E5=AE=89?= Date: Wed, 25 Feb 2026 09:31:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor(logging):=20=E6=94=B9=E8=BF=9B?= =?UTF-8?q?=E8=B4=A6=E6=88=B7=E6=A8=A1=E5=9E=8B=E4=B8=AD=E7=9A=84=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=AE=B0=E5=BD=95=E7=BA=A7=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将账户模型中的日志记录级别从 info 调整为 debug,以减少日志冗余并提高调试信息的可读性。同时,优化了配置重新加载的日志记录逻辑,确保只记录一次,避免重复日志输出。此改动提升了代码的可维护性与日志管理效率。 --- backend/database/models.py | 6 +++--- trading_system/main.py | 10 ++-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/backend/database/models.py b/backend/database/models.py index dce48dc..761f9fd 100644 --- a/backend/database/models.py +++ b/backend/database/models.py @@ -53,10 +53,10 @@ class Account: def get(account_id: int): import logging logger = logging.getLogger(__name__) - logger.info(f"Account.get called with account_id={account_id}") + logger.debug("Account.get called with account_id=%s", account_id) row = db.execute_one("SELECT * FROM accounts WHERE id = %s", (int(account_id),)) if row: - logger.info(f"Account.get: found account_id={account_id}, name={row.get('name', 'N/A')}, status={row.get('status', 'N/A')}") + logger.debug("Account.get: found account_id=%s, name=%s, status=%s", account_id, row.get('name', 'N/A'), row.get('status', 'N/A')) else: logger.warning(f"Account.get: account_id={account_id} not found in database") return row @@ -135,7 +135,7 @@ class Account: """ import logging logger = logging.getLogger(__name__) - logger.info(f"Account.get_credentials called with account_id={account_id}") + logger.debug("Account.get_credentials called with account_id=%s", account_id) row = Account.get(account_id) if not row: logger.warning(f"Account.get_credentials: account_id={account_id} not found in database") diff --git a/trading_system/main.py b/trading_system/main.py index b099ed9..b8364dc 100644 --- a/trading_system/main.py +++ b/trading_system/main.py @@ -198,12 +198,6 @@ async def main(): if config.USE_DB_CONFIG: logger.info("✓ 使用数据库配置") - # 尝试重新加载配置(确保获取最新值) - try: - config.reload_config() - logger.info("配置已重新加载") - except Exception as e: - logger.warning(f"重新加载配置失败: {e}", exc_info=True) else: logger.warning("⚠ 未使用数据库配置,将使用环境变量和默认配置") logger.warning("如果前端已配置API密钥,请检查:") @@ -211,8 +205,8 @@ async def main(): logger.warning("2. 数据库连接是否正常") logger.warning("3. config_manager模块是否可以正常导入") logger.warning("4. 数据库配置表中是否有BINANCE_API_KEY和BINANCE_API_SECRET") - - # 强制重新加载配置(确保使用最新值) + + # 统一在此重新加载配置(只打一次日志,避免重复) try: config.reload_config() logger.info("配置已重新加载")