Skip to content

feat: adapt dynamic logging rules for debug config mode - #416

Merged
deepin-bot[bot] merged 4 commits into
linuxdeepin:masterfrom
add-uos:feat/debug-config-logrules
Oct 22, 2026
Merged

deepin-bot[bot] merged 4 commits into
linuxdeepin:masterfrom
add-uos:feat/debug-config-logrules

Conversation

@add-uos

@add-uos add-uos commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

改动说明

看图(deepin-image-viewer)调试模式完整适配,参考 deepin-reader 的 MLogger 方案(DTK6 6.7.50 无 registerLoggingRulesWatcher,采用自管 DConfig 方案)。

1. 日志分类化补全

  • 存量 qDebug/qWarning 全部替换为 qCDebug/qCWarning(logImageViewer)(分类 org.deepin.dde.imageviewer):
    • src/src/ocr/ocrinterface.h(openImage/openImageAndName)
    • src/src/unionimage/imageutils.cpp
  • xraw 插件日志分类化到 org.deepin.dde.imageviewer.libraw(子模块,挂在本应用前缀下)

2. MLogger 动态日志监听

  • 新增 src/src/logger.h / src/src/logger.cpp:先 qunsetenv("QT_LOGGING_RULES")(任何日志打印之前),再读 DConfig log_rules 并 setFilterRules(分隔符 ; → \n),监听 valueChanged 实现运行中动态切换
  • main.cpp 在任何日志打印、Application 实例化之前创建 MLogger 实例

3. DConfig meta + CMake 安装

  • 新增 assets/configs/org.deepin.dde.imageviewer.json(log_rules 配置项,默认值 warning=true 放最后)
  • src/CMakeLists.txt 安装到 share/dsg/configs/org.deepin.dde.imageviewer/(DTK6 走 dtk_add_config_meta_files)

4. 修复 xraw 插件 keys 回归

  • qimage-plugins/libraw/raw.json 的 Keys 列表被早期提交清空为 {},导致 Qt 插件系统无法实例化该插件(Qt 按 metadata Keys 选择 handler);恢复原始 Keys 列表(crw/cr2/arw/nef/raf/dng)

验证

  • 基于 master(868f29a5)rebase 后重新编译通过(Qt6 + DTK6 6.7.50)
  • 运行核对逐级切换:debug 全出 → info 剩 qCInfo/qCWarning → warning 只剩 qCWarning
  • 只出本应用分类日志,debug/info 规则均限定 org.deepin.dde.imageviewer*,无 Qt 框架日志混入
  • 运行中动态切换验证(不重启,dde-dconfig --set 后新日志立即生效)
  • xraw 插件运行单元验证(RAW 图解码时插件分类日志出现)
  • SPDX 年份检查器(license-check 流水线同款)本地实跑:5 个含 UnionTech 头的改动文件全部通过,新文件年份 2026、改动文件年份范围均含当前年;json 文件不在 include 列表,rawiohandler.cpp 保留上游版权头被忽略

PMS: TASK-396789

Summary by Sourcery

Enable dynamic, application-scoped logging configuration and restore RAW plugin format support.

New Features:

  • Add runtime-configurable logging rules backed by DConfig, allowing debug-mode changes to take effect without restarting the application.

Bug Fixes:

  • Restore RAW image plugin format metadata so Qt can instantiate the LibRaw handler correctly.

Enhancements:

  • Complete categorization of application and LibRaw diagnostic output for targeted logging control.

Build:

  • Install the image viewer DConfig metadata during the build.

Add MLogger to watch DConfig log_rules and switch log levels at runtime;
categorize remaining unclassified logs; install DConfig meta json.

新增 MLogger 监听 DConfig log_rules 实现运行中动态切换日志级别,
补全存量日志分类化,并新增 DConfig meta 配置与 CMake 安装规则。

Log: 看图动态日志规则调试模式适配
PMS: TASK-396789
Influence: 调试模式下可通过 debug-config 动态开关看图各级别日志。
Restore the Keys list in raw.json overwritten to empty by earlier
commits so the xraw plugin is loadable; categorize plugin logs under
org.deepin.dde.imageviewer.libraw.

恢复 raw.json 中被清空的 Keys 列表使 xraw 插件在 Qt6 下可被加载,
并将插件日志分类化到 org.deepin.dde.imageviewer.libraw。

Log: 恢复raw插件keys并分类化插件日志
PMS: TASK-396789
Influence: RAW 图片经 xraw 插件解码,插件日志纳入统一分类管理。
@github-actions

Copy link
Copy Markdown
  • 检测到敏感词unset变动
详情
    {
    "unset": {
        "src/main.cpp": {
            "b": [
                "    // \uff08qunsetenv(\"QT_LOGGING_RULES\") \u4e4b\u524d\u4e0d\u80fd\u6709\u65e5\u5fd7\u8f93\u51fa\uff0c\u53c2\u8003 deepin-reader MLogger\uff09"
            ]
        },
        "src/src/logger.cpp": {
            "b": [
                "    // qunsetenv \u4e4b\u524d\u4e00\u5b9a\u4e0d\u8981\u6709\u4efb\u4f55\u65e5\u5fd7\u6253\u5370\uff0c\u5426\u5219\u53d6\u6d88\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u4e0d\u4f1a\u751f\u6548",
                "    qunsetenv(\"QT_LOGGING_RULES\");"
            ]
        }
    }
}

@sourcery-ai

sourcery-ai Bot commented Oct 21, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR completes debug-mode logging integration by introducing an early-starting, DConfig-watched filter manager, categorizing application and RAW-plugin logs under controllable namespaces, installing the associated configuration metadata, and restoring RAW plugin format keys.

Sequence diagram for dynamic logging rule updates

sequenceDiagram
    participant Main
    participant MLogger
    participant DConfig
    participant QLoggingCategory

    Main->>MLogger: MLogger()
    MLogger->>MLogger: qunsetenv(QT_LOGGING_RULES)
    MLogger->>DConfig: create(org.deepin.dde.imageviewer)
    MLogger->>DConfig: value(log_rules)
    MLogger->>QLoggingCategory: setFilterRules(rules)
    DConfig-->>MLogger: valueChanged(log_rules)
    MLogger->>DConfig: value(log_rules)
    MLogger->>QLoggingCategory: setFilterRules(rules)
Loading

File-Level Changes

Change Details Files
Adds a DConfig-backed logging manager that initializes before application startup and applies logging rules dynamically at runtime.
  • Clears inherited QT_LOGGING_RULES before logging begins.
  • Loads log_rules from DConfig and converts semicolon-delimited rules to Qt filter-rule format.
  • Updates logging filters when the DConfig value changes.
  • Registers the manager in main before any application initialization.
src/src/logger.h
src/src/logger.cpp
src/main.cpp
Converts application and RAW-plugin messages to named logging categories for debug-mode filtering.
  • Replaces remaining qDebug/qWarning calls with categorized qCDebug/qCWarning calls.
  • Defines the application category org.deepin.dde.imageviewer and RAW subcategory org.deepin.dde.imageviewer.libraw.
  • Keeps plugin logs under the application namespace for wildcard rule control.
src/src/ocr/ocrinterface.h
src/src/unionimage/imageutils.cpp
qimage-plugins/libraw/rawiohandler.cpp
Adds and installs the DConfig metadata required to expose dynamic logging rules.
  • Defines the log_rules setting with warning-level logging enabled by default.
  • Installs configuration metadata under the application-specific DSG config directory.
  • Uses DTK6 config-meta integration when available and a direct install fallback otherwise.
assets/configs/org.deepin.dde.imageviewer.json
src/CMakeLists.txt
Restores RAW image plugin metadata keys so Qt can select the plugin for supported formats.
  • Restores CRW, CR2, ARW, NEF, RAF, and DNG keys in the plugin metadata.
qimage-plugins/libraw/raw.json

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 2 issues

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

## Individual Comments

### Comment 1
<location path="src/src/logger.cpp" line_range="29" />
<code_context>
+
+#ifdef DTKCORE_CLASS_DConfigFile
+    // set dconfig
+    m_config = DConfig::create("org.deepin.dde.imageviewer", "org.deepin.dde.imageviewer");
+    logRules = m_config->value("log_rules").toByteArray();
+    appendRules(logRules);
</code_context>
<issue_to_address>
**Startup crashes without DConfig**

When DConfig creation fails because its backend or metadata is unavailable, `MLogger` dereferences the null `m_config` while reading `log_rules`, so startup crashes before the application object is created.

Check `m_config` before reading or connecting to it, and continue with the environment rules when creation fails.

Also at `src/src/logger.cpp:30-31`.
</issue_to_address>

### Comment 2
<location path="src/src/logger.cpp" line_range="38" />
<code_context>
+    // LCOV_EXCL_START
+    connect(m_config, &DConfig::valueChanged, this, [this](const QString &key) {
+        if (key == "log_rules") {
+            setRules(m_config->value(key).toByteArray());
+        }
+    });
</code_context>
<issue_to_address>
**Environment rules disappear after changes**

When `QT_LOGGING_RULES` contains rules and DConfig emits a `log_rules` change at runtime, the `valueChanged` handler passes only the DConfig value to `setRules`, replacing the rules merged during construction; environment-only categories stop following their configured rules.

Retain the environment rules and combine them with the updated DConfig rules before calling `setRules`.

Also at `src/src/logger.cpp:39`.
</issue_to_address>

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

Comment thread src/src/logger.cpp Resolved
Comment thread src/src/logger.cpp Outdated
// LCOV_EXCL_START
connect(m_config, &DConfig::valueChanged, this, [this](const QString &key) {
if (key == "log_rules") {
setRules(m_config->value(key).toByteArray());

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 · Environment rules disappear after changes

When QT_LOGGING_RULES contains rules and DConfig emits a log_rules change at runtime, the valueChanged handler passes only the DConfig value to setRules, replacing the rules merged during construction; environment-only categories stop following their configured rules.

Retain the environment rules and combine them with the updated DConfig rules before calling setRules.

Also at src/src/logger.cpp:39.

Prompt for AI agents
In `src/src/logger.cpp` at line 38:

**Environment rules disappear after changes**

When `QT_LOGGING_RULES` contains rules and DConfig emits a `log_rules` change at runtime, the `valueChanged` handler passes only the DConfig value to `setRules`, replacing the rules merged during construction; environment-only categories stop following their configured rules.

Retain the environment rules and combine them with the updated DConfig rules before calling `setRules`.

Also at `src/src/logger.cpp:39`.

- Null-check DConfig::create() so startup falls back to env rules when
  the meta config is unavailable
- Clarify in comments that DConfig is the single runtime authority and
  env rules are only a bootstrap fallback
- Deduplicate rules by exact line match in appendRules
- Unify raw.json Keys formatting; drop quotes on CMake EQUAL 6

按审查意见加固 MLogger:DConfig 创建失败时空指针保护并回退环境变量
规则;注释明确 DConfig 为运行时唯一权威来源;appendRules 改为按行
精确去重;统一 raw.json Keys 格式;CMake 数值比较去引号。

Log: 按代码审查意见加固 MLogger
PMS: TASK-396789
@github-actions

Copy link
Copy Markdown
  • 检测到敏感词unset变动
详情
    {
    "unset": {
        "src/main.cpp": {
            "b": [
                "    // \uff08qunsetenv(\"QT_LOGGING_RULES\") \u4e4b\u524d\u4e0d\u80fd\u6709\u65e5\u5fd7\u8f93\u51fa\uff0c\u53c2\u8003 deepin-reader MLogger\uff09"
            ]
        },
        "src/src/logger.cpp": {
            "b": [
                "    // qunsetenv \u4e4b\u524d\u4e00\u5b9a\u4e0d\u8981\u6709\u4efb\u4f55\u65e5\u5fd7\u6253\u5370\uff0c\u5426\u5219\u53d6\u6d88\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u4e0d\u4f1a\u751f\u6548",
                "    qunsetenv(\"QT_LOGGING_RULES\");"
            ]
        }
    }
}

Drop the extra "dde" segment in the logging category and DConfig
appId/configuration_id; rename the DConfig meta file accordingly.

日志分类与 DConfig appId/configuration_id 去掉多余 dde 段改为
org.deepin.imageviewer,同步重命名 DConfig meta 配置文件。

Log: 日志分类改为org.deepin.imageviewer
PMS: TASK-396789
@github-actions

Copy link
Copy Markdown
  • 检测到敏感词unset变动
详情
    {
    "unset": {
        "src/main.cpp": {
            "b": [
                "    // \uff08qunsetenv(\"QT_LOGGING_RULES\") \u4e4b\u524d\u4e0d\u80fd\u6709\u65e5\u5fd7\u8f93\u51fa\uff0c\u53c2\u8003 deepin-reader MLogger\uff09"
            ]
        },
        "src/src/logger.cpp": {
            "b": [
                "    // qunsetenv \u4e4b\u524d\u4e00\u5b9a\u4e0d\u8981\u6709\u4efb\u4f55\u65e5\u5fd7\u6253\u5370\uff0c\u5426\u5219\u53d6\u6d88\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u4e0d\u4f1a\u751f\u6548",
                "    qunsetenv(\"QT_LOGGING_RULES\");"
            ]
        }
    }
}

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 98 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为 deepin-image-viewer 引入基于 DConfig 的动态日志规则管理(MLogger),并将 qDebug/qWarning 迁移为分类日志(qCDebug/qCWarning)。代码逻辑清晰,注释完整,无安全漏洞。仅存在少量代码质量改进空间(去重逻辑边界、分隔符转换重复),整体质量优秀。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['无语法逻辑问题,代码结构清晰']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['appendRules 中应先将 m_rules 的分号也替换为换行符后再拆分,确保去重逻辑一致', '将分号到换行符的替换逻辑抽取为统一的 normalizeRules 私有方法,减少重复']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['无性能问题,分类日志迁移是积极的性能改进']


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: ['无安全漏洞,代码安全合规']


💡 改进建议代码示例

// 建议将分号到换行符的替换逻辑统一抽取,并修正 appendRules 去重逻辑
QString MLogger::normalizeSeparators(const QString &rules) const
{
    return QString(rules).replace(";", "\n");
}

void MLogger::appendRules(const QString &rules)
{
    // 先将 m_rules 也统一为换行符分隔,确保去重逻辑一致
    const QString normalizedExisting = normalizeSeparators(m_rules);
    const QStringList existing = normalizedExisting.split('\n', Qt::SkipEmptyParts);
    const QStringList adding = normalizeSeparators(rules).split('\n', Qt::SkipEmptyParts);

    QStringList toAdd;
    for (const QString &rule : adding) {
        if (!existing.contains(rule) && !toAdd.contains(rule)) {
            toAdd.append(rule);
        }
    }
    if (toAdd.isEmpty())
        return;
    m_rules.isEmpty() ? m_rules = toAdd.join("\n")
                      : m_rules += "\n" + toAdd.join("\n");
}

本报告由 AI 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, lzwind

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

@add-uos

add-uos commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit ace8761 into linuxdeepin:master Oct 22, 2026
16 of 17 checks passed
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.

3 participants