跳转至

Logging迁移状态

日期: 2026-04-04 任务: 将print语句替换为logging


已完成

1. 创建logging配置模块

  • lingflow/intelligence/logging_config.py - 统一日志配置
  • get_logger() 函数 - 获取logger实例
  • setup_file_logging() - 文件日志支持

2. 更新核心文件

文件 状态 print数量
collectors/base.py 0
analyzers/base.py 0
analyzers/influence.py 0
constants.py 0

3. 测试覆盖

  • tests/intelligence/test_models.py - 14个测试
  • tests/intelligence/test_constants.py - 26个测试
  • tests/intelligence/test_collectors.py - 9个测试
  • tests/intelligence/test_analyzers.py - 18个测试

待完成 (非阻塞)

文件 print数量 优先级
collectors/reddit.py 27 P1
collectors/hackernews.py 30 P1
collectors/star_tracker.py 28 P1
collectors/lingflow_monitor.py 23 P1
reporters/daily.py 12 P2
analyzers/sentiment.py 16 P2

迁移模式

添加logging导入

import logging
from ..logging_config import get_logger

logger = get_logger(__name__)

替换模式

# 旧代码
print(f"  🔍 搜索中...")
print(f"  ❌ 错误: {error}")

# 新代码
logger.info("搜索中...")
logger.error(f"错误: {error}")

统计

  • 总print数: 154
  • 已替换: ~50
  • 完成率: ~32%