diff --git a/agents/haonan/workspace/dev-workflow/stats.py b/agents/haonan/workspace/dev-workflow/stats.py index 6561bf1..f06f7da 100644 --- a/agents/haonan/workspace/dev-workflow/stats.py +++ b/agents/haonan/workspace/dev-workflow/stats.py @@ -9,11 +9,15 @@ import json import os import tempfile import fcntl +import logging from datetime import datetime from pathlib import Path from typing import Dict, List, Any, Optional from collections import defaultdict +# 配置日志 +logger = logging.getLogger(__name__) + # 统计数据存储路径 STATS_DIR = Path(__file__).parent / "data" STATS_FILE = STATS_DIR / "stats_data.json" @@ -170,8 +174,10 @@ def record_event( _atomic_write(data) return True + except TypeError: + raise # 重新抛出类型错误 except Exception as e: - print(f"记录事件失败: {e}") + logger.error(f"记录事件失败: {e}") return False @@ -301,7 +307,7 @@ def clear_stats(confirm: bool = False) -> bool: STATS_FILE.unlink() return True except Exception as e: - print(f"清空统计数据失败: {e}") + logger.error(f"清空统计数据失败: {e}") return False