[Refactor]【Hackathon 9th No.88】Refactor log printing [cf]#7713
[Refactor]【Hackathon 9th No.88】Refactor log printing [cf]#7713ghost wants to merge 1 commit intoPaddlePaddle:developfrom
Conversation
|
Thanks for your contribution! |
CI报告基于以下代码生成(30分钟更新一次): 1 任务总览✅ 所有已执行的 CI 任务均通过。7 个 Workflow 处于
2 任务状态汇总2.1 Required任务 : 0/0 通过
2.2 可选任务 — 2/2 通过
3 失败详情(仅 required)无 |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-05-03 21:44:35
📋 Review 摘要
PR 概述:为日志打印重构任务(Hackathon 9th No.88)添加单元测试文件 tests/test_logging.py
变更范围:tests/test_logging.py(新增)
影响面 Tag:[Others]
📝 PR 规范检查
标题使用了非官方 Tag [Refactor],且描述中各 section 均为 <!-- TODO --> 占位符,需要填写实际内容。
标题建议(可直接复制):
[Others] Add unit tests for FastDeploy logging infrastructure (Hackathon 9th No.88)
PR 描述建议(可直接复制,必须复刻 checklist §D2 模板的完整结构):
## Motivation
为日志打印重构任务(Hackathon 9th No.88)补充单元测试,验证 `fastdeploy.logger` 模块的核心行为,包括 `get_logger()` 命名规范、`FD_LOG_LEVEL` 环境变量控制、`FastDeployLogger` 单例模式、控制台 Handler 注册,以及 legacy 兼容接口。
## Modifications
- 新增 `tests/test_logging.py`,包含以下测试类:
- `TestGetLogger`:验证 `get_logger()` 返回正确命名的 logger 实例
- `TestFDLogLevel`:验证 `FD_LOG_LEVEL` / `FD_DEBUG` 环境变量的优先级逻辑
- `TestFastDeployLoggerSingleton`:验证 `FastDeployLogger` 单例模式
- `TestConsoleHandler`:验证统一 logger 中 StreamHandler 的注册
- `TestLegacyGetLogger`:验证向后兼容的 legacy `get_logger(name, file)` 接口
## Usage or Command
```bash
python -m pytest tests/test_logging.py -v
```
## Accuracy Tests
N/A
## Checklist
- [x] Add at least a tag in the PR title.
- Tag list: [`[FDConfig]`,`[APIServer]`,`[Engine]`, `[Scheduler]`, `[PD Disaggregation]`, `[Executor]`, `[Graph Optimization]`, `[Speculative Decoding]`, `[RL]`, `[Models]`, `[Quantization]`, `[Loader]`, `[OP]`, `[KVCache]`, `[DataProcessor]`, `[BugFix]`, `[Docs]`, `[CI]`, `[Optimization]`, `[Feature]`, `[Benchmark]`, `[Others]`, `[XPU]`, `[HPU]`, `[GCU]`, `[DCU]`, `[Iluvatar]`, `[Metax]`]
- You can add new tags based on the PR content, but the semantics must be clear.
- [ ] Format your code, run `pre-commit` before commit.
- [x] Add unit tests. Please write the reason in this PR if no unit tests.
- [ ] Provide accuracy results.
- [ ] If the current PR is submitting to the `release` branch, make sure the PR has been submitted to the `develop` branch, then cherry-pick it to the `release` branch with the `[Cherry-Pick]` PR tag.问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🔴 Bug | tests/test_logging.py:64 |
get_logger(None) 实际返回 "fastdeploy.main" 而非 "fastdeploy",断言失败 |
| 🔴 Bug | tests/test_logging.py:76 |
get_logger("scheduler") 实际返回 "fastdeploy.main.scheduler" 而非 "fastdeploy.scheduler",断言失败 |
| 🔴 Bug | tests/test_logging.py:92 |
envs.FD_LOG_LEVEL 默认为 None,断言期望 "INFO" 将失败 |
| 🔴 Bug | tests/test_logging.py:130 |
setup_logging() 返回 None,访问 .handlers 将抛出 AttributeError |
总体评价
测试文件结构完整、覆盖面合理,但存在 4 处断言与实际实现不符的问题,运行时将全部失败,需修复后方可合入。
| from fastdeploy.logger import get_logger | ||
|
|
||
| logger = get_logger(None) | ||
| self.assertEqual(logger.name, "fastdeploy") |
There was a problem hiding this comment.
🔴 Bug get_logger(None) 实际返回名为 "fastdeploy.main" 的 logger,而非 "fastdeploy"。
原因:_get_channel_logger(None, "main") 中,当 name is None 时,返回的是 channel_logger,其名称为 f"fastdeploy.{channel}" 即 "fastdeploy.main"。
建议修复:
# 修改断言以匹配实际命名
self.assertEqual(logger.name, "fastdeploy.main")| from fastdeploy.logger import get_logger | ||
|
|
||
| logger = get_logger("scheduler") | ||
| self.assertEqual(logger.name, "fastdeploy.scheduler") |
There was a problem hiding this comment.
🔴 Bug get_logger("scheduler") 实际返回名为 "fastdeploy.main.scheduler" 的 logger,而非 "fastdeploy.scheduler"。
原因:_get_channel_logger 中普通名称被拼接为 f"{channel_root_name}.{name}",即 "fastdeploy.main.scheduler"。
建议修复:
# 修改断言以匹配实际命名
self.assertEqual(logger.name, "fastdeploy.main.scheduler")| from fastdeploy import envs | ||
|
|
||
| level = envs.FD_LOG_LEVEL | ||
| self.assertEqual(level, "INFO") |
There was a problem hiding this comment.
🔴 Bug envs.FD_LOG_LEVEL 的默认值为 None,而非 "INFO"。
原因:envs.py 中 FD_LOG_LEVEL 定义为 lambda: os.getenv("FD_LOG_LEVEL", None),未设置时返回 None。
建议修复(二选一):
- 修改断言:
self.assertIsNone(level) - 或在测试中读取
resolve_log_level()函数而非envs.FD_LOG_LEVEL
|
|
||
|
|
||
| @unittest.skipUnless(HAS_PADDLE, SKIP_MSG) | ||
| class TestConsoleHandler(unittest.TestCase): |
There was a problem hiding this comment.
🔴 Bug setup_logging() 无返回值(返回 None),对 None 调用 .handlers 将抛出 AttributeError: 'NoneType' object has no attribute 'handlers'。
原因:setup_logging 函数本身不创建或返回 logger 对象,仅做目录初始化和可选的 dictConfig。
建议修复:
from fastdeploy.logger.setup_logging import setup_logging
from fastdeploy.logger.logger import FastDeployLogger
setup_logging()
fd_logger = FastDeployLogger()._get_channel_logger(None, "console")
handler_classes = [type(h).__name__ for h in fd_logger.handlers]
Motivation
Modifications
Usage or Command
Accuracy Tests
Checklist