Skip to content

[BugFix] Fix legacy logger propagation leaking unformatted logs to stderr#7617

Open
gongweibao wants to merge 1 commit intoPaddlePaddle:developfrom
gongweibao:addtimestamp
Open

[BugFix] Fix legacy logger propagation leaking unformatted logs to stderr#7617
gongweibao wants to merge 1 commit intoPaddlePaddle:developfrom
gongweibao:addtimestamp

Conversation

@gongweibao
Copy link
Copy Markdown
Collaborator

Motivation

Legacy loggers (legacy.*) created by get_trace_logger() and _get_legacy_logger() had propagate left as True (commented out since PR #3431). This caused all log levels (INFO/WARNING/ERROR) to propagate to the Python root logger, which outputs to stderr using the default LEVEL:name:message format — without timestamps.

Impact:

  • stderr log files (*-stderr.log) are polluted with INFO-level logs that shouldn't be there
  • ERROR logs in stderr have no timestamps, causing downstream tools (e.g. paddlerl diagnose) to display (no ts) and fail to filter events by time

Root cause: PR #3431 introduced the legacy.* namespace (logging.getLogger(f"legacy.{name}")) but kept logger.propagate = False commented out with the note "maintain original logic". The original code didn't need it because loggers were at the top level. After the namespace change, legacy.api_server became a child of the root logger, and propagation leaked all logs to stderr.

Modifications

  • Uncomment logger.propagate = False in both get_trace_logger() and _get_legacy_logger()
  • Update test assertion from assertTrue to assertFalse to match the fix

Usage or Command

No usage change. After this fix:

  • stderr only contains ERROR-level logs from channel loggers (with proper %(asctime)s timestamps)
  • INFO/WARNING logs from legacy loggers no longer leak to stderr

Accuracy Tests

N/A — logging-only change, no impact on model outputs.

Checklist

  • Add at least a tag in the PR title.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Test updated to match fix, 109 tests all passing.
  • 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.

…derr

Legacy loggers (legacy.*) had propagate=True (commented out since PaddlePaddle#3431),
causing all log levels to propagate to the root logger and output to stderr
without timestamps. This made downstream log parsers unable to extract
timestamps from stderr log files.

Set propagate=False for both get_trace_logger and _get_legacy_logger so
logs only go through their configured handlers with proper formatting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 24, 2026 13:34
@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented Apr 24, 2026

Thanks for your contribution!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

该 PR 修复 get_trace_logger() / _get_legacy_logger() 创建的 legacy.* logger 默认向 root logger 传播,导致日志以 root logger 的默认格式泄漏到 stderr(缺少期望的格式/时间戳)的问题,使 legacy logger 的输出与 FastDeploy 的日志体系隔离。

Changes:

  • get_trace_logger()_get_legacy_logger() 中显式设置 logger.propagate = False
  • 更新单元测试断言,使其与新的传播行为一致

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
fastdeploy/logger/logger.py 禁用 legacy logger 向 root logger 的传播,避免 stderr 被未格式化日志污染
tests/logger/test_logger.py 更新 legacy logger 的 propagate 断言以匹配修复后的行为
Comments suppressed due to low confidence (1)

tests/logger/test_logger.py:88

  • 本次同时修改了 get_trace_logger()logger.propagate 行为(改为 False),但当前测试只覆盖了 _get_legacy_logger() 的 propagate。建议在 test_get_trace_logger_basic(或单独用例)里也断言 logger.propagate 为 False,避免后续回归。
        legacy_logger = self.logger._get_legacy_logger("test", "test.log")
        self.assertFalse(legacy_logger.propagate)

    def test_get_trace_logger_basic(self):
        """Test basic functionality of get_trace_logger"""
        logger = self.logger.get_trace_logger("test_trace", "trace_test.log")

@@ -246,8 +246,7 @@ def get_trace_logger(self, name, file_name, without_formater=False, print_to_con
logger.addHandler(console_handler)
console_handler.propagate = False
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

这里对 console_handler 设置 propagate 没有实际效果:propagatelogging.Logger 的属性,不是 logging.Handler 的属性。该行会让人误以为 handler 能控制传播,建议删除该行,统一由 logger.propagate = False 控制。

Suggested change
console_handler.propagate = False

Copilot uses AI. Check for mistakes.
@@ -311,8 +310,7 @@ def _get_legacy_logger(self, name, file_name, without_formater=False, print_to_c
logger.addHandler(console_handler)
console_handler.propagate = False
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

这里对 console_handler 设置 propagate 没有实际效果:propagatelogging.Logger 的属性,不是 logging.Handler 的属性。建议删除该行,避免误导,统一由 logger.propagate = False 控制。

Suggested change
console_handler.propagate = False

Copilot uses AI. Check for mistakes.
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.

🤖 AI Code Review | 2026-04-24 21:37:03

📋 Review 摘要

PR 概述:修复 legacy.* 命名空间下的 logger 因 propagate=True 导致日志泄漏到 stderr 的问题。
变更范围fastdeploy/logger/logger.pytests/logger/test_logger.py
影响面 TagBugFix

问题

级别 文件 概述
🟡 建议 tests/logger/test_logger.py:84 get_trace_logger() 同样被修复,但缺少对应的 propagate=False 测试断言

总体评价

修复思路正确,根因分析清晰,PR 描述详尽。仅建议在测试中补充 get_trace_logger()propagate 断言,保持两处修复的测试覆盖对称。

"""Test log propagation settings"""
legacy_logger = self.logger._get_legacy_logger("test", "test.log")
self.assertTrue(legacy_logger.propagate)
self.assertFalse(legacy_logger.propagate)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 建议 get_trace_logger() 缺少 propagate 测试覆盖

本次 PR 同时修复了 get_trace_logger()_get_legacy_logger() 中的 propagate 设置,但测试用例 test_logger_propagate 仅验证了 _get_legacy_logger() 的行为,get_trace_logger() 缺少对应断言。

建议补充:

def test_logger_propagate(self):
    """Test log propagation settings"""
    legacy_logger = self.logger._get_legacy_logger("test", "test.log")
    self.assertFalse(legacy_logger.propagate)
    # Also verify get_trace_logger
    trace_logger = self.logger.get_trace_logger("test_trace", "test_trace.log")
    self.assertFalse(trace_logger.propagate)

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@791484a). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #7617   +/-   ##
==========================================
  Coverage           ?   71.67%           
==========================================
  Files              ?      419           
  Lines              ?    57856           
  Branches           ?     9077           
==========================================
  Hits               ?    41467           
  Misses             ?    13561           
  Partials           ?     2828           
Flag Coverage Δ
GPU 71.67% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

4 participants