Repository navigation
feat: add debug mode support with dynamic log level control - #63
Conversation
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
|
Warning
详情 {
"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\");"
]
}
}
} |
Reviewer's GuideAdds 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 controlsequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析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个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例// 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 代码审查工具自动生成 |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: unstable) |
变更说明(Changes)
为 deepin-picker(取色器)做 debug 模式(deepin-debug-config)适配:
src/ddlog.h(org.deepin.picker日志分类)与src/logger.h/.cpp(MLogger,参考 deepin-reader 方案),将 4 个源文件共 40 处qDebug/qInfo/qWarning全部改为qCDebug/qCInfo/qCWarning(appLog),日志严格限定在本应用分类下,debug/info 规则不会波及其他组件。main()中在 Application 构造前优先创建栈对象MLogger:读取并清除QT_LOGGING_RULES环境变量,通过 DConfig 读取log_rules并应用;监听DConfig::valueChanged,支持调试模式下 不重启应用动态切换 debug/info/warning 级别。assets/configs/org.deepin.picker.json,log_rules默认值仅开启 warning 级别,并通过 qmakedconfig_meta安装至/usr/share/dsg/configs/org.deepin.picker/。配套 deepin-debug-config 侧 json + shell:Gerrit https://gerrit.uniontech.com/c/deepin-debug-config/+/407249
验证(Verification)
QT_NO_DEBUG,不涉及QT_NO_DEBUG_OUTPUT)qCWarning;debug 全量输出(启动链路 17 条分类日志);info 仅剩qCInfo/qCWarninglog_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:
Enhancements:
Build: