fix: avoid duplicate logging under systemd with journal#543
Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom Feb 27, 2026
Merged
fix: avoid duplicate logging under systemd with journal#543deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
Conversation
Contributor
Author
BLumia
reviewed
Feb 26, 2026
BLumia
previously approved these changes
Feb 27, 2026
Member
这个别忘了 @mhduiy |
1. Updated debian/control to require libdtklog-dev and libdtk6log-dev versions greater than 6.7.33 2. Added shouldSkipConsoleAppender() method to detect when running under systemd with stdout connected to journal 3. Modified initConsoleAppender() to skip console appender initialization when journal appender is active under systemd 4. Modified initJournalAppender() to unregister existing console appender when journal appender is initialized under systemd 5. Added environment variable DTK_FORCE_CONSOLE_LOGGING to override the behavior if needed The changes prevent duplicate log output when applications run under systemd with journal logging enabled, since systemd automatically redirects stdout to journal. This avoids having both console and journal appenders writing the same logs. fix: 避免在 systemd 下使用 journal 时重复日志输出 1. 更新 debian/control 以要求 libdtklog-dev 和 libdtk6log-dev 版本大 于 6.7.33 2. 添加 shouldSkipConsoleAppender() 方法检测是否在 systemd 环境下运行且 标准输出已连接到 journal 3. 修改 initConsoleAppender() 在 systemd 下且 journal appender 激活时跳 过控制台 appender 初始化 4. 修改 initJournalAppender() 在 systemd 下初始化 journal appender 时注 销已存在的控制台 appender 5. 添加环境变量 DTK_FORCE_CONSOLE_LOGGING 用于在需要时覆盖此行为 这些更改防止了在 systemd 环境下运行且启用 journal 日志记录时出现重复日 志输出,因为 systemd 会自动将标准输出重定向到 journal。这避免了控制台和 journal appender 同时写入相同日志的问题。
Contributor
deepin pr auto review这份代码变更主要涉及日志管理系统的改进,包括依赖更新、许可证调整以及核心日志逻辑的优化。以下是对语法逻辑、代码质量、代码性能和代码安全方面的详细审查意见: 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
总结与改进建议这份代码变更整体质量很高,主要解决了 systemd 环境下的日志重复问题,并更新了依赖和版权信息。 主要改进建议:
示例代码优化(微小的健壮性增强): 虽然当前代码处理得不错,但在解析环境变量时,可以稍微增加一点对空部分的检查,尽管 // 在 shouldSkipConsoleAppender 中
auto parts = journalStream.split(':');
// 确保分割后正好有两部分,且都不为空
if (parts.size() != 2 || parts[0].isEmpty() || parts[1].isEmpty())
return false;总体而言,这是一个逻辑清晰、安全且实用的改进。 |
BLumia
approved these changes
Feb 27, 2026
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: BLumia, mhduiy The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Contributor
Author
|
/forcemerge |
Contributor
|
This pr force merged! (status: blocked) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The changes prevent duplicate log output when applications run under systemd with journal logging enabled, since systemd automatically redirects stdout to journal. This avoids having both console and journal appenders writing the same logs.
fix: 避免在 systemd 下使用 journal 时重复日志输出
这些更改防止了在 systemd 环境下运行且启用 journal 日志记录时出现重复日
志输出,因为 systemd 会自动将标准输出重定向到 journal。这避免了控制台和
journal appender 同时写入相同日志的问题。