Skip to content

feat: add debug mode support with dynamic log level control - #63

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:feat/picker-debugsource
Oct 23, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:feat/picker-debugsource

Conversation

@add-uos

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

Copy link
Copy Markdown
Contributor

变更说明(Changes)

为 deepin-picker(取色器)做 debug 模式(deepin-debug-config)适配:

  1. 分类日志改造:新增 src/ddlog.h(org.deepin.picker 日志分类)与 src/logger.h/.cpp(MLogger,参考 deepin-reader 方案),将 4 个源文件共 40 处 qDebug/qInfo/qWarning 全部改为 qCDebug/qCInfo/qCWarning(appLog),日志严格限定在本应用分类下,debug/info 规则不会波及其他组件。
  2. 动态日志规则监听:main() 中在 Application 构造前优先创建栈对象 MLogger:读取并清除 QT_LOGGING_RULES 环境变量,通过 DConfig 读取 log_rules 并应用;监听 DConfig::valueChanged,支持调试模式下 不重启应用动态切换 debug/info/warning 级别。
  3. DConfig meta:新增 assets/configs/org.deepin.picker.json,log_rules 默认值仅开启 warning 级别,并通过 qmake dconfig_meta 安装至 /usr/share/dsg/configs/org.deepin.picker/。
  4. qmake 工程同步登记新文件(HEADERS/SOURCES/INSTALLS)。

配套 deepin-debug-config 侧 json + shell:Gerrit https://gerrit.uniontech.com/c/deepin-debug-config/+/407249

验证(Verification)

  • qmake6 + make 构建通过(release 默认定义 QT_NO_DEBUG,不涉及 QT_NO_DEBUG_OUTPUT)
  • 运行时逐级验证:warning(默认)仅剩 qCWarning;debug 全量输出(启动链路 17 条分类日志);info 仅剩 qCInfo/qCWarning
  • 运行中进程通过 dde-dconfig 修改 log_rules 后无需重启即时生效(valueChanged 监听验证)
  • *.debug=true 等规则严格限定 org.deepin.picker* 前缀,无全局规则,框架 debug 日志不受影响

Log: Add debug mode adaptation for deepin-picker
Influence: 日志改为分类日志输出,默认仅 warning 级别输出,其余行为不变

Summary by Sourcery

Enable deepin-picker debug mode with application-scoped logs and runtime log-level control.

New Features:

  • Add application-scoped categorized logging with configurable debug, info, and warning output levels.
  • Support changing the application's logging rules dynamically through DConfig without restarting the picker.

Enhancements:

  • Consolidate existing picker logs under the org.deepin.picker logging category while preserving normal application behavior.

Build:

  • Register the logger sources and DConfig metadata in the qmake project and install the metadata with the application.

Categorized logging (org.deepin.picker) + MLogger self-managed DConfig
log_rules dynamic watching + dconfig meta default rules, for
deepin-debug-config adaptation.

Log: Add debug mode adaptation for deepin-picker
Influence: Change to categorized logging, only warning level is output by default
@sourcery-ai

sourcery-ai Bot commented Oct 22, 2026

Copy link
Copy Markdown

Sorry @add-uos, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 days and 18 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@github-actions

Copy link
Copy Markdown
  • 检测到敏感词unset变动
详情
    {
    "unset": {
        "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 22, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds application-scoped categorized logging for deepin-picker, initializes rules before Qt application startup, and supports live debug/info/warning level changes through DConfig while installing a warning-only default configuration.

Sequence diagram for dynamic deepin-picker log rule control

sequenceDiagram
    participant Process
    participant MLogger
    participant DConfig
    participant QLoggingCategory
    participant Picker as deepin-picker

    Process->>MLogger: MLogger()
    MLogger->>MLogger: qgetenv(QT_LOGGING_RULES)
    MLogger->>MLogger: qunsetenv(QT_LOGGING_RULES)
    MLogger->>DConfig: create(org.deepin.picker, org.deepin.picker)
    DConfig-->>MLogger: value(log_rules)
    MLogger->>MLogger: appendRules(log_rules)
    MLogger->>QLoggingCategory: setRules(m_rules)
    MLogger->>DConfig: connect(valueChanged)
    Process->>Picker: construct DApplication and start
    DConfig-->>MLogger: valueChanged(log_rules)
    MLogger->>DConfig: value(log_rules)
    MLogger->>QLoggingCategory: setRules(log_rules)
    QLoggingCategory-->>Picker: apply updated debug/info/warning filtering
Loading

File-Level Changes

Change Details Files
Introduces centralized, application-scoped categorized logging and replaces the existing unscoped Qt logging calls.
  • Defines the org.deepin.picker logging category.
  • Converts debug, info, and warning output across the application to category-aware macros.
  • Preserves warning/error visibility while allowing debug and info output to be filtered independently.
src/ddlog.h
src/animation.cpp
src/colormenu.cpp
src/cpickermanager.cpp
src/main.cpp
Adds startup initialization and live DConfig-backed log rule management without requiring an application restart.
  • Constructs MLogger before DApplication and any application logging.
  • Removes the inherited QT_LOGGING_RULES environment variable before applying rules.
  • Merges DConfig rules with existing environment rules at startup and updates Qt filter rules when log_rules changes.
  • Provides a compatibility path when DConfig support is unavailable.
src/logger.h
src/logger.cpp
src/main.cpp
Adds and installs application DConfig metadata providing the default logging policy.
  • Defines the log_rules configuration for org.deepin.picker with warning-only defaults.
  • Installs the metadata under the DConfig system configuration directory.
assets/configs/org.deepin.picker.json
deepin-picker.pro
Registers the new logging implementation and metadata in the qmake build and installation configuration.
  • Adds logger headers and implementation to the project.
  • Adds the DConfig metadata installation target.
deepin-picker.pro

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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为 deepin-picker 添加基于 DConfig 的动态日志级别控制功能,整体架构清晰、注释完整、安全无漏洞。存在1处潜在的空指针解引用风险(DConfig::create() 返回值未做 null 检查)和1处 appendRules 子串匹配逻辑不精确问题,建议修复后合入。

🔍 详细分析

1. 语法逻辑 ❌

评价: 存在逻辑缺陷 ❌ 不通过

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

建议: ['在 DConfig::create() 之后添加 if (m_config) 判空保护,null 时走 fallback 路径直接调用 setRules(m_rules)', '将 m_rules 按换行符拆分为 QStringList 后使用 QList::contains() 做精确匹配,而非对整个字符串做子串匹配']


2. 代码质量 ✅

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

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

建议: ['考虑使用 QScopedPointer 或 std::unique_ptr 管理 m_config 生命周期,提升代码健壮性']


3. 代码性能 ✅

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

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

建议: ['析构函数中改用 delete m_config 替代 deleteLater(),确保在事件循环停止后资源仍能正确释放']


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// src/logger.cpp - 修复空指针解引用和子串匹配问题
MLogger::MLogger(QObject *parent)
    : QObject(parent), m_rules("")
#ifdef DTKCORE_CLASS_DConfigFile
    , m_config(nullptr)
#endif {
    QByteArray logRules = qgetenv("QT_LOGGING_RULES");
    qunsetenv("QT_LOGGING_RULES");
    m_rules = logRules;

#ifdef DTKCORE_CLASS_DConfigFile
    m_config = DConfig::create("org.deepin.picker", "org.deepin.picker");
    if (m_config) {
        logRules = m_config->value("log_rules").toByteArray();
        appendRules(logRules);
        setRules(m_rules);

        connect(m_config, &DConfig::valueChanged, this, [this](const QString &key) {
            if (key == "log_rules") {
                setRules(m_config->value(key).toByteArray());
            }
        });
    } else {
        setRules(m_rules);
    }
#else
    setRules(m_rules);
#endif }
// 修复 appendRules 子串匹配问题:使用精确匹配 void MLogger::appendRules(const QString &rules) {
    QString tmpRules = rules;
    tmpRules = tmpRules.replace(";", "\n");
    auto tmplist = tmpRules.split('\n');
    auto existingRules = m_rules.split('\n');
    for (int i = 0; i < tmplist.count(); ) {
        if (existingRules.contains(tmplist.at(i))) {
            tmplist.removeAt(i);
        } else {
            i++;
        }
    }
    if (tmplist.isEmpty())
        return;
    m_rules.isEmpty() ? m_rules = tmplist.join("\n")
                      : m_rules += "\n" + tmplist.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 23, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 72a562f into linuxdeepin:master Oct 23, 2026
15 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