refactor: 统一日志管理 + 数据库索引优化

- db/schema.py: 添加 4 个复合索引优化查询性能
  - idx_user_schedules_user_enabled
  - idx_schedule_execution_logs_schedule_id/user_id/status
- db/users.py: print → logger,密码升级日志改为记录 user_id
- crypto_utils.py: print → logger
- password_utils.py: print → logger

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-23 22:57:03 +08:00
parent c5f019be5a
commit 5f4fb50001
4 changed files with 19 additions and 8 deletions

View File

@@ -12,6 +12,8 @@ from pathlib import Path
from cryptography.fernet import Fernet
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from app_logger import get_logger
logger = get_logger(__name__)
# 安全修复: 支持通过环境变量配置密钥文件路径
@@ -65,7 +67,7 @@ def get_encryption_key():
os.makedirs(key_path.parent, exist_ok=True)
with open(key_path, 'wb') as f:
f.write(key)
print(f"[安全] 已生成新的加密密钥并保存到 {ENCRYPTION_KEY_FILE}")
logger.info(f"已生成新的加密密钥并保存到 {ENCRYPTION_KEY_FILE}")
return key
@@ -119,7 +121,7 @@ def decrypt_password(encrypted_password: str) -> str:
return decrypted.decode('utf-8')
except Exception as e:
# 解密失败,可能是旧的明文密码
print(f"[警告] 密码解密失败,可能是未加密的旧数据: {e}")
logger.warning(f"密码解密失败,可能是未加密的旧数据: {e}")
return encrypted_password