Skip to content

release#31

Merged
Oscaner merged 20 commits intoreleasefrom
main
Feb 1, 2026
Merged

release#31
Oscaner merged 20 commits intoreleasefrom
main

Conversation

@Oscaner
Copy link
Member

@Oscaner Oscaner commented Feb 1, 2026

No description provided.

Oscaner and others added 20 commits January 19, 2026 15:01
Sync release to main after release
Bumps the development-dependencies group with 1 update: [commitizen](https://github.com/commitizen-tools/commitizen).


Updates `commitizen` from 4.11.6 to 4.12.0
- [Release notes](https://github.com/commitizen-tools/commitizen/releases)
- [Changelog](https://github.com/commitizen-tools/commitizen/blob/master/CHANGELOG.md)
- [Commits](commitizen-tools/commitizen@v4.11.6...v4.12.0)

---
updated-dependencies:
- dependency-name: commitizen
  dependency-version: 4.12.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: development-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
…ncies-543a7f8f97

chore(deps-dev): bump commitizen from 4.11.6 to 4.12.0 in the development-dependencies group
Bumps the development-dependencies group with 2 updates: [ruff](https://github.com/astral-sh/ruff) and [commitizen](https://github.com/commitizen-tools/commitizen).


Updates `ruff` from 0.14.13 to 0.14.14
- [Release notes](https://github.com/astral-sh/ruff/releases)
- [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md)
- [Commits](astral-sh/ruff@0.14.13...0.14.14)

Updates `commitizen` from 4.12.0 to 4.12.1
- [Release notes](https://github.com/commitizen-tools/commitizen/releases)
- [Changelog](https://github.com/commitizen-tools/commitizen/blob/master/CHANGELOG.md)
- [Commits](commitizen-tools/commitizen@v4.12.0...v4.12.1)

---
updated-dependencies:
- dependency-name: ruff
  dependency-version: 0.14.14
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: development-dependencies
- dependency-name: commitizen
  dependency-version: 4.12.1
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: development-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
…ncies-ed8e4ab727

chore(deps-dev): bump the development-dependencies group with 2 updates
Bumps the development-dependencies group with 1 update: [hypothesis](https://github.com/HypothesisWorks/hypothesis).


Updates `hypothesis` from 6.150.2 to 6.151.0
- [Release notes](https://github.com/HypothesisWorks/hypothesis/releases)
- [Commits](HypothesisWorks/hypothesis@hypothesis-python-6.150.2...hypothesis-python-6.151.0)

---
updated-dependencies:
- dependency-name: hypothesis
  dependency-version: 6.151.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: development-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
…ncies-cb5805e16e

chore(deps-dev): bump hypothesis from 6.150.2 to 6.151.0 in the development-dependencies group
- 实现 LogCleaner 类,支持按时间和大小清理日志
- 添加环境变量配置日志清理策略
- 应用启动时自动初始化日志清理器
- 提供完整的测试覆盖(10个测试用例)
- 添加详细的功能文档

功能特性:
- 按时间清理:自动删除超过指定天数的日志文件(默认7天)
- 按大小清理:当日志目录超过限制时删除最旧的文件(默认100MB)
- 定期执行:在后台线程中自动运行(默认每24小时)
- 灵活配置:通过环境变量轻松配置清理策略
- 统计信息:提供日志目录的详细统计

测试结果:170/170 tests passed ✅
- 使用 keyword-only 参数解决 __init__ 参数过多问题
- 创建 _LogCleanerState 类避免使用 global 语句
- 所有测试通过,功能正常
- 使用 TimedRotatingFileHandler 替代普通 FileHandler
- 每天午夜自动创建新的日志文件
- 文件命名格式:flow_proxy_plugin.log.YYYY-MM-DD
- backupCount=0,让 log_cleaner 管理历史文件
- 更新文档说明日志轮转机制

优势:
- 日志文件按日期组织,便于查找和管理
- 避免单个文件过大
- 配合自动清理功能,自动删除过期日志
- 更语义化的环境变量名称
- 只需指定日志目录,文件名固定为 flow_proxy_plugin.log
- 更新所有相关文件:cli.py, logging.py, .env.example, README.md
- 修复 MyPy 类型检查(传递 Path 对象而非 str)
- 所有测试通过(170/170)

修改前:FLOW_PROXY_LOG_FILE=flow_proxy_plugin.log
修改后:FLOW_PROXY_LOG_DIR=logs

优势:
- 目录和文件概念分离更清晰
- 与日志清理器的 log_dir 参数一致
- 符合常见的配置命名规范
- 将变量名 log_file 改为 base_log_file,更清晰地表达基础文件路径
- 添加详细的内联注释,说明 TimedRotatingFileHandler 的工作机制
- 明确说明当前日志和归档日志的命名规则
- 强调轮转时机(午夜)和间隔(每天)

改进前:
  log_file = str(log_dir_path / "flow_proxy_plugin.log")

改进后:
  base_log_file = log_dir_path / "flow_proxy_plugin.log"
  # 详细注释说明按天轮转机制

这使得代码意图更加清晰,避免误解为固定的单一文件。
- 添加 30 个测试用例覆盖所有日志组件
- 测试配置类 (FormatConfig, RotationConfig, CleanupConfig, LogConfig)
- 测试工厂类 (LoggerFactory) 创建 handler
- 测试设置类 (LogSetup) 的完整设置流程
- 测试公共函数 (setup_logging, setup_colored_logger)
- 测试环境变量配置加载
- 测试 TimedRotatingFileHandler 的实际行为
- 使用 mock 隔离外部依赖
- 使用 tmp_path fixture 测试文件操作

测试覆盖范围:
- Colors 类: 1 个测试
- ColoredFormatter: 2 个测试
- FormatConfig: 2 个测试
- RotationConfig: 2 个测试
- CleanupConfig: 3 个测试
- LogConfig: 7 个测试
- LoggerFactory: 3 个测试
- LogSetup: 4 个测试
- setup_logging: 2 个测试
- setup_colored_logger: 4 个测试

总计: 30 个测试,全部通过
总测试数量从 170 增加到 200
问题分析:
- setup_colored_logger 默认设置 propagate=False
- 导致插件的日志只输出到控制台,不传播到 root logger
- root logger 的 file handler 无法接收插件日志

解决方案:
- 在 BaseFlowProxyPlugin._setup_logging 中设置 propagate=True
- 使插件日志同时输出到控制台(彩色)和文件(通过 root logger)

影响:
- 插件日志现在会正确写入日志文件
- 控制台输出保持彩色
- 所有测试通过 (200/200)

已知问题:
- 日志文件中包含 ANSI 颜色代码(将在后续提交中修复)
问题根源:
- proxy.py 使用多进程模式(fork workers)
- 主进程调用 setup_logging() 设置 root logger 的 file handler
- 子进程继承了主进程,但 Python logging handlers 在多进程环境下可能失效
- 插件在子进程中初始化,之前的 propagate=True 方案依赖 root logger
- 但子进程的 root logger file handler 可能已经失效

解决方案:
- 不再依赖 propagate,改为直接复制 root logger 的 file handler
- 在插件的 _setup_logging() 中:
  1. 使用 setup_colored_logger 设置控制台输出(propagate=False)
  2. 遍历 root logger 的 handlers
  3. 将 file handlers 直接添加到插件 logger
- 这样即使在子进程中,插件 logger 也有自己的 file handler

效果:
- 插件日志在多进程环境下正确写入文件
- 控制台保持彩色输出
- 避免日志重复(propagate=False)
- 所有测试通过 (200/200)
- 在 logging.py 中添加 setup_file_handler_for_child_process 函数
- 该函数在子进程中创建新的文件处理器,而不是复制父进程的处理器
- 修改 base_plugin.py 使用新函数在子进程中重新初始化文件处理器
- 在 cli.py 中设置 FLOW_PROXY_LOG_DIR 环境变量供子进程使用
- 解决了 fork 后文件描述符和锁失效导致日志无法写入的问题
- 添加 7 个新测试用例覆盖不同场景
- 测试默认参数、自定义日志级别、移除旧处理器等功能
- 测试从环境变量读取配置
- 测试创建新处理器而非复制
- 测试不同日志目录的处理
- 修复函数确保日志目录存在
- 修复 mypy 类型检查错误
- 所有 33 个测试通过
Update the environment variable from FLOW_PROXY_LOG_FILE to
FLOW_PROXY_LOG_DIR to specify the log directory instead of a specific
log file. This allows the application to manage log file naming and
rotation internally while maintaining logs in the /app/logs/ directory.
Bumps the development-dependencies group with 1 update: [hypothesis](https://github.com/HypothesisWorks/hypothesis).


Updates `hypothesis` from 6.151.0 to 6.151.3
- [Release notes](https://github.com/HypothesisWorks/hypothesis/releases)
- [Commits](HypothesisWorks/hypothesis@hypothesis-python-6.151.0...hypothesis-python-6.151.3)

---
updated-dependencies:
- dependency-name: hypothesis
  dependency-version: 6.151.3
  dependency-type: direct:development
  update-type: version-update:semver-patch
  dependency-group: development-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
…ncies-b1f664a2ff

chore(deps-dev): bump hypothesis from 6.151.0 to 6.151.3 in the development-dependencies group
@Oscaner Oscaner merged commit 2253fe7 into release Feb 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant