Skip to content

fix(log): reorder file appender init after app name - #546

Open
Resurgamz wants to merge 1 commit into
linuxdeepin:release/eaglefrom
Resurgamz:fix/log-file-path-order
Open

Resurgamz wants to merge 1 commit into
linuxdeepin:release/eaglefrom
Resurgamz:fix/log-file-path-order

Conversation

@Resurgamz

@Resurgamz Resurgamz commented Dec 2, 2026 •

Copy link
Copy Markdown

问题

正式包(release/eagle 线,6.0.13)运行日志未写入预期路径 ~/.cache/deepin/deepin-camera/deepin-camera.log,而是写到了 ~/.cache/.log,排查问题时找不到对应日志。

根因

提交 d2d696e 将 DLogManager::registerFileAppender() 提前到 main() 开头。此时 QApplication 尚未创建,organizationName() / applicationName() 均为空,DTK 按 $XDG_CACHE_HOME/<org>/<app>/<app>.log 计算得到 ~/.cache/.log。此外早期调用的 getlogFilePath() 会把错误路径缓存到 m_logPath。

修改

  • 保留 registerConsoleAppender() 提前注册,启动早期日志仍输出到控制台;
  • 将 registerFileAppender() 与 LogFile 打印移动到 setOrganizationName() / setApplicationName() 之后;
  • 移除早期会缓存错误路径的 getlogFilePath() 调用。

验证

  • Release 构建通过;
  • 本机用修复后二进制实跑,日志正确写入 ~/.cache/deepin/deepin-camera/deepin-camera.log,LogFile: 打印正确路径;
  • ~/.cache/.log 不再新增内容;
  • 全新 XDG_CACHE_HOME 下目录可自动创建。

备注

该问题为 d2d696e 引入的回归,仅影响 release/eagle 线;master 已采用新的日志系统,不存在此问题。

Summary by Sourcery

Bug Fixes:

  • Write file logs under the cache path derived from the configured organization and application names instead of the incorrect ~/.cache/.log path.

Register the file log appender after QApplication creation and
setApplicationName so the log path uses a valid application name.

将文件日志 appender 的注册移动到设置应用名之后,避免应用名为空时
DTK 将路径计算为 ~/.cache/.log;同时移除会缓存错误路径的早期
getlogFilePath 调用。

Log: 修复运行日志写入错误路径的问题
Influence: 运行日志恢复到 ~/.cache/deepin/deepin-camera/deepin-camera.log,启动早期日志仍输出到控制台。
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Resurgamz

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Reviewer's Guide

Uses of the API

Keep console logging registered early, but register the file appender and print its path only after the organization and application names are set.

  • src/main.cpp L133-136, L332-335

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/main.cpp" line_range="334" />
<code_context>
+    // 控制台日志尽早注册,确保启动阶段日志不遗漏
     //qputenv("QT_LOGGING_RULES", "*.debug=true;*.info=true");
     DLogManager::registerConsoleAppender();
-    DLogManager::registerFileAppender();
-    qInfo() << "LogFile:" << DLogManager::getlogFilePath();
+    // 文件日志路径依赖 organizationName/applicationName,必须在设置应用名后再注册
</code_context>
<issue_to_address>
**Startup diagnostics disappear from log**

When startup diagnostics are emitted before the file appender is registered, earlier `qInfo()`, `qWarning()`, and `qDebug()` calls run before `DLogManager::registerFileAppender()`, so they reach only the console and are not replayed to the file; inspecting the persistent log therefore omits startup diagnostics.

Register the file appender after the application name is set but before emitting startup diagnostics.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/main.cpp
qApp->setApplicationName("deepin-camera");
// 文件日志依赖 organizationName/applicationName 计算路径,
// 必须在应用名设置完成后再注册,否则会写到 ~/.cache/.log
DLogManager::registerFileAppender();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Startup diagnostics disappear from log

When startup diagnostics are emitted before the file appender is registered, earlier qInfo(), qWarning(), and qDebug() calls run before DLogManager::registerFileAppender(), so they reach only the console and are not replayed to the file; inspecting the persistent log therefore omits startup diagnostics.

Register the file appender after the application name is set but before emitting startup diagnostics.

Prompt for AI agents
In `src/main.cpp` at line 334:

**Startup diagnostics disappear from log**

When startup diagnostics are emitted before the file appender is registered, earlier `qInfo()`, `qWarning()`, and `qDebug()` calls run before `DLogManager::registerFileAppender()`, so they reach only the console and are not replayed to the file; inspecting the persistent log therefore omits startup diagnostics.

Register the file appender after the application name is set but before emitting startup diagnostics.

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.

2 participants