refactor(logging): 改进账户模型中的日志记录级别

将账户模型中的日志记录级别从 info 调整为 debug,以减少日志冗余并提高调试信息的可读性。同时,优化了配置重新加载的日志记录逻辑,确保只记录一次,避免重复日志输出。此改动提升了代码的可维护性与日志管理效率。
This commit is contained in:
薇薇安 2026-02-25 09:31:35 +08:00
parent 163b8303ec
commit 9086c15f2e
2 changed files with 5 additions and 11 deletions

View File

@ -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")

View File

@ -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("配置已重新加载")