Skip to content

[Refactor]【Hackathon 9th No.88】Refactor log printing [cf]#7713

Open
ghost wants to merge 1 commit intoPaddlePaddle:developfrom
CloudForge-Solutions:task/088-refactor-log-printing-v3
Open

[Refactor]【Hackathon 9th No.88】Refactor log printing [cf]#7713
ghost wants to merge 1 commit intoPaddlePaddle:developfrom
CloudForge-Solutions:task/088-refactor-log-printing-v3

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented May 2, 2026

Motivation

Modifications

Usage or Command

Accuracy Tests

Checklist

  • I have submitted the CLA (only first PR)
  • My PR title follows the convention
  • My changes pass all tests

@ghost ghost temporarily deployed to Metax_ci May 2, 2026 17:15 — with GitHub Actions Inactive
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 2, 2026

CLA assistant check
All committers have signed the CLA.

@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented May 2, 2026

Thanks for your contribution!

@paddle-bot paddle-bot Bot added the contributor External developers label May 2, 2026
PaddlePaddle-bot

This comment was marked as outdated.

@PaddlePaddle-bot
Copy link
Copy Markdown

PaddlePaddle-bot commented May 2, 2026

🤖 Paddle-CI-Agent | ci_status_monitor | 2026-05-03 21:59:16

CI报告基于以下代码生成(30分钟更新一次):


1 任务总览

✅ 所有已执行的 CI 任务均通过。7 个 Workflow 处于 action_required 状态,等待人工审批触发。

总执行(rerun次数) 总任务 ✅ 通过 ❌ 失败 ⏳ 运行中 ⏸️ 等待中 跳过
2(0) 2 2 0 0 0 0

⚠️ 注意:以下 7 个 Workflow 处于 action_required 状态(等待审批后才会执行):Codestyle-Check、Check PR Template、Approval、CI_HPU、CI_XPU、PR Build and Test、ILUVATAR-CI。这些 Workflow 需人工审批触发。

注意:action_required workflows 不计入上表的任务统计。


2 任务状态汇总

2.1 Required任务 : 0/0 通过

当前 PR 无必选任务配置(Branch Protection Rules 未配置 Required Status Checks)。

2.2 可选任务 — 2/2 通过

可选任务不阻塞合并,失败仅供参考。

状态 任务 耗时 日志 重跑
其余 2 个可选任务通过 - - -

3 失败详情(仅 required)

Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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 处断言与实际实现不符的问题,运行时将全部失败,需修复后方可合入。

Comment thread tests/test_logging.py
from fastdeploy.logger import get_logger

logger = get_logger(None)
self.assertEqual(logger.name, "fastdeploy")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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")

Comment thread tests/test_logging.py
from fastdeploy.logger import get_logger

logger = get_logger("scheduler")
self.assertEqual(logger.name, "fastdeploy.scheduler")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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")

Comment thread tests/test_logging.py
from fastdeploy import envs

level = envs.FD_LOG_LEVEL
self.assertEqual(level, "INFO")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug envs.FD_LOG_LEVEL 的默认值为 None,而非 "INFO"

原因:envs.pyFD_LOG_LEVEL 定义为 lambda: os.getenv("FD_LOG_LEVEL", None),未设置时返回 None

建议修复(二选一):

  1. 修改断言:self.assertIsNone(level)
  2. 或在测试中读取 resolve_log_level() 函数而非 envs.FD_LOG_LEVEL

Comment thread tests/test_logging.py


@unittest.skipUnless(HAS_PADDLE, SKIP_MSG)
class TestConsoleHandler(unittest.TestCase):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants