Repository navigation
feat: adapt dynamic logging rules for debug config mode - #416
Conversation
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 插件解码,插件日志纳入统一分类管理。
|
Warning
详情 {
"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\");"
]
}
}
} |
Reviewer's GuideThis 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 updatessequenceDiagram
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)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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>| // LCOV_EXCL_START | ||
| connect(m_config, &DConfig::valueChanged, this, [this](const QString &key) { | ||
| if (key == "log_rules") { | ||
| setRules(m_config->value(key).toByteArray()); |
There was a problem hiding this comment.
🟡 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
|
Warning
详情 {
"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
|
Warning
详情 {
"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 pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: ['无语法逻辑问题,代码结构清晰'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['appendRules 中应先将 m_rules 的分号也替换为换行符后再拆分,确保去重逻辑一致', '将分号到换行符的替换逻辑抽取为统一的 normalizeRules 私有方法,减少重复'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['无性能问题,分类日志迁移是积极的性能改进'] 4. 代码安全 🔒评价: 存在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 代码审查工具自动生成 |
|
[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) |
改动说明
看图(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.cpporg.deepin.dde.imageviewer.libraw(子模块,挂在本应用前缀下)2. MLogger 动态日志监听
src/src/logger.h/src/src/logger.cpp:先qunsetenv("QT_LOGGING_RULES")(任何日志打印之前),再读 DConfiglog_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)验证
org.deepin.dde.imageviewer*,无 Qt 框架日志混入PMS: TASK-396789
Summary by Sourcery
Enable dynamic, application-scoped logging configuration and restore RAW plugin format support.
New Features:
Bug Fixes:
Enhancements:
Build: