Repository navigation
feat: categorize logs and register dynamic dconfig log watcher - #101
Conversation
|
Warning
详情 {
"unset": {
"src/main.cpp": {
"b": [
" // \u52a8\u6001\u65e5\u5fd7\u76d1\u542c\u5fc5\u987b\u5728\u4efb\u4f55\u65e5\u5fd7\u6253\u5370\u4e4b\u524d\u521b\u5efa\uff08qunsetenv \u624d\u80fd\u751f\u6548\uff09\uff0c"
]
},
"src/util/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\");"
]
}
}
} |
|
TAG Bot TAG: 6.5.17 |
Reviewer's GuideAdapts deepin-ocr to dynamic, category-scoped logging by introducing a process-lifetime DConfig-backed filter, migrating diagnostics to the org.deepin.ocr category, and installing matching DConfig metadata and CMake support. Sequence diagram for dynamic OCR logging configurationsequenceDiagram
participant Main
participant MLogger
participant DConfig
participant QLoggingCategory
Main->>MLogger: MLogger()
MLogger->>MLogger: qunsetenv(QT_LOGGING_RULES)
MLogger->>DConfig: create(org.deepin.ocr, org.deepin.ocr)
MLogger->>DConfig: value(log_rules)
MLogger->>QLoggingCategory: setFilterRules(log_rules)
DConfig-->>MLogger: valueChanged(log_rules)
MLogger->>DConfig: value(log_rules)
MLogger->>QLoggingCategory: setFilterRules(log_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 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/util/logger.cpp" line_range="31-32" />
<code_context>
+
+#ifdef DTKCORE_CLASS_DConfig
+ // set dconfig
+ m_config = DConfig::create("org.deepin.ocr", "org.deepin.ocr");
+ logRules = m_config->value("log_rules").toByteArray();
+ appendRules(logRules);
+ setRules(m_rules);
</code_context>
<issue_to_address>
**Application exits during startup**
When DConfig::create returns null, `MLogger` immediately dereferences `m_config` to read `log_rules`, so construction terminates the process before the application starts.
Check `m_config` before reading `log_rules` and continue with the captured environment rules when creation fails.
</issue_to_address>
### Comment 2
<location path="src/util/logger.cpp" line_range="39" />
<code_context>
+ // watch dconfig
+ 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 filters stop applying**
When environment rules are set and `log_rules` changes at runtime, `setRules()` replaces the initially merged filter set with only the DConfig value, so environment-configured filters stop applying and logging behavior changes.
Rebuild the active rules from both the environment rules and the updated DConfig value before calling `setRules()`.
</issue_to_address>
### Comment 3
<location path="src/util/logger.cpp" line_range="70" />
<code_context>
+ tmpRules = tmpRules.replace(";", "\n");
+ auto tmplist = tmpRules.split('\n');
+ for (int i = 0; i < tmplist.count(); i++)
+ if (m_rules.contains(tmplist.at(i))) {
+ tmplist.removeAt(i);
+ i--;
</code_context>
<issue_to_address>
**Substring match suppresses DConfig rules**
When an environment rule contains a DConfig rule as a substring but is not the same rule, `m_rules.contains` treats any substring match as a duplicate, so an environment rule such as `xorg.deepin.ocr*.debug=false` suppresses the distinct DConfig rule `org.deepin.ocr*.debug=false`. The DConfig policy is then not applied, and the application category follows other matching rules or Qt defaults instead.
Compare normalized individual rules for exact equality rather than using substring containment.
</issue_to_address>
### Comment 4
<location path="src/util/logger.cpp" line_range="61" />
<code_context>
+ auto tmpRules = rules;
+ // Qt 限制:setFilterRules 的规则分隔符必须为 \n,不能是 ;
+ m_rules = tmpRules.replace(";", "\n");
+ QLoggingCategory::setFilterRules(m_rules);
+}
+
</code_context>
<issue_to_address>
**Framework debug logs remain enabled**
When A Qt/framework category emits debug or info messages while the app’s logging rules are active, `setFilterRules` applies only the app-category rules from DConfig; Qt categories that do not match them retain Qt’s default filter, so their debug and info messages appear alongside app logs instead of remaining excluded.
Add explicit wildcard rules to disable debug/info for unmatched categories, then enable the requested levels for `org.deepin.ocr*`.
</issue_to_address>| m_config = DConfig::create("org.deepin.ocr", "org.deepin.ocr"); | ||
| logRules = m_config->value("log_rules").toByteArray(); |
There was a problem hiding this comment.
🟠 High · Application exits during startup
When DConfig::create returns null, MLogger immediately dereferences m_config to read log_rules, so construction terminates the process before the application starts.
Check m_config before reading log_rules and continue with the captured environment rules when creation fails.
Prompt for AI agents
In `src/util/logger.cpp` at lines 31-32:
**Application exits during startup**
When DConfig::create returns null, `MLogger` immediately dereferences `m_config` to read `log_rules`, so construction terminates the process before the application starts.
Check `m_config` before reading `log_rules` and continue with the captured environment rules when creation fails.| // watch dconfig | ||
| 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 filters stop applying
When environment rules are set and log_rules changes at runtime, setRules() replaces the initially merged filter set with only the DConfig value, so environment-configured filters stop applying and logging behavior changes.
Rebuild the active rules from both the environment rules and the updated DConfig value before calling setRules().
Prompt for AI agents
In `src/util/logger.cpp` at line 39:
**Environment filters stop applying**
When environment rules are set and `log_rules` changes at runtime, `setRules()` replaces the initially merged filter set with only the DConfig value, so environment-configured filters stop applying and logging behavior changes.
Rebuild the active rules from both the environment rules and the updated DConfig value before calling `setRules()`.| tmpRules = tmpRules.replace(";", "\n"); | ||
| auto tmplist = tmpRules.split('\n'); | ||
| for (int i = 0; i < tmplist.count(); i++) | ||
| if (m_rules.contains(tmplist.at(i))) { |
There was a problem hiding this comment.
🟡 Medium · Substring match suppresses DConfig rules
When an environment rule contains a DConfig rule as a substring but is not the same rule, m_rules.contains treats any substring match as a duplicate, so an environment rule such as xorg.deepin.ocr*.debug=false suppresses the distinct DConfig rule org.deepin.ocr*.debug=false. The DConfig policy is then not applied, and the application category follows other matching rules or Qt defaults instead.
Compare normalized individual rules for exact equality rather than using substring containment.
Prompt for AI agents
In `src/util/logger.cpp` at line 70:
**Substring match suppresses DConfig rules**
When an environment rule contains a DConfig rule as a substring but is not the same rule, `m_rules.contains` treats any substring match as a duplicate, so an environment rule such as `xorg.deepin.ocr*.debug=false` suppresses the distinct DConfig rule `org.deepin.ocr*.debug=false`. The DConfig policy is then not applied, and the application category follows other matching rules or Qt defaults instead.
Compare normalized individual rules for exact equality rather than using substring containment.| auto tmpRules = rules; | ||
| // Qt 限制:setFilterRules 的规则分隔符必须为 \n,不能是 ; | ||
| m_rules = tmpRules.replace(";", "\n"); | ||
| QLoggingCategory::setFilterRules(m_rules); |
There was a problem hiding this comment.
🟡 Medium · Framework debug logs remain enabled
When A Qt/framework category emits debug or info messages while the app’s logging rules are active, setFilterRules applies only the app-category rules from DConfig; Qt categories that do not match them retain Qt’s default filter, so their debug and info messages appear alongside app logs instead of remaining excluded.
Add explicit wildcard rules to disable debug/info for unmatched categories, then enable the requested levels for org.deepin.ocr*.
Prompt for AI agents
In `src/util/logger.cpp` at line 61:
**Framework debug logs remain enabled**
When A Qt/framework category emits debug or info messages while the app’s logging rules are active, `setFilterRules` applies only the app-category rules from DConfig; Qt categories that do not match them retain Qt’s default filter, so their debug and info messages appear alongside app logs instead of remaining excluded.
Add explicit wildcard rules to disable debug/info for unmatched categories, then enable the requested levels for `org.deepin.ocr*`.f93e198 to
d6ce535
Compare
|
Warning
详情 {
"unset": {
"src/main.cpp": {
"b": [
" // \u52a8\u6001\u65e5\u5fd7\u76d1\u542c\u5fc5\u987b\u5728\u4efb\u4f55\u65e5\u5fd7\u6253\u5370\u4e4b\u524d\u521b\u5efa\uff08qunsetenv \u624d\u80fd\u751f\u6548\uff09\uff0c"
]
},
"src/util/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\");"
]
}
}
} |
80e1e48 to
30bdbd3
Compare
- Rename logging category dmOcr from deepin.ocr to org.deepin.ocr - Replace remaining qDebug/qInfo/qWarning with qC* category macros - Add MLogger to read dconfig log_rules (appId org.deepin.ocr) and apply Qt filter rules dynamically via valueChanged, created before Application instance
30bdbd3 to
12d0fa5
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ❌评价: 存在逻辑缺陷 ❌ 不通过 潜在问题: 建议: ['valueChanged 回调中应先重置 m_rules 为环境变量规则,再调用 appendRules 合并新的 DConfig 规则,最后 setRules,与构造函数保持一致', '析构函数中应使用 delete m_config 并置空指针,而非 deleteLater(),确保在事件循环停止后仍能正确释放', 'appendRules 中应将 m_rules 按行拆分为 QStringList 后使用精确匹配去重,而非 substring contains'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['将', '将三元运算符赋值改为 if/else 语句提升可读性'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例// === src/util/logger.cpp 修复示例 ===
// 修复1: valueChanged 回调应保持与构造函数一致的合并语义
// 修复前:
// connect(m_config, &DConfig::valueChanged, this, [this](const QString &key) {
// if (key == "log_rules") {
// setRules(m_config->value(key).toByteArray());
// }
// });
// 修复后:
connect(m_config, &DConfig::valueChanged, this, [this](const QString &key) {
if (key == "log_rules") {
// 重置为环境变量规则,再合并新的 DConfig 规则,保持与构造函数一致
m_rules = qgetenv("QT_LOGGING_RULES");
appendRules(m_config->value(key).toByteArray());
setRules(m_rules);
}
});
// 修复2: 析构函数使用 delete 替代 deleteLater
MLogger::~MLogger()
{
#ifdef DTKCORE_CLASS_DConfig
if (m_config) {
delete m_config;
m_config = nullptr;
}
#endif
}
// 修复3: appendRules 使用精确行匹配替代 substring contains
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(); i++) {
if (existingRules.contains(tmplist.at(i))) {
tmplist.removeAt(i);
i--;
}
}
if (tmplist.isEmpty())
return;
if (m_rules.isEmpty()) {
m_rules = tmplist.join("\n");
} else {
m_rules += "\n" + tmplist.join("\n");
}
}
// === src/util/logger.h 修复示例 ===
// 修复4: #endif 注释与 include guard 一致
// 修复前: #endif // LOGGER_H
// 修复后:
#endif // DEEPIN_OCR_LOGGER_H本报告由 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 |
|
/merge |
概要:deepin-ocr 调试模式适配——Part 1/2:日志分类化 + 动态日志监听(10 个文件)
配套提交:Part 2/2(dconfig meta + 安装规则,3 个文件)单独一个 PR;deepin-debug-config 侧 json + shell 在 Gerrit develop/snipe 另行提交。
改动内容(本 PR 10 个文件)
日志分类化
dmOcr由deepin.ocr规范为org.deepin.ocr(src/util/log.cpp)qCDebug/qCInfo/qCWarning(dmOcr)动态日志监听(
src/util/logger.h/.cpp,参考 deepin-reader MLogger)MLogger:DConfig::create("org.deepin.ocr", "org.deepin.ocr")读取log_rules并QLoggingCategory::setFilterRules应用qunsetenv("QT_LOGGING_RULES")(在任何日志打印之前),规则分隔符;→\n后再设置DConfig::valueChanged,运行中切换调试级别即时生效(无需重启)main()中在 Application 实例化之前创建,实例存活整个进程编译宏排查:仓库无
QT_NO_DEBUG_OUTPUT/QT_NO_WARNING_OUTPUT有效定义(Release 打包不受影响)验证
dde-dconfig --set+ MLogger valueChanged,全程未重启进程):warning(默认)→ debug(全出)→ info(qCDebug 消失)→ warning(分类日志 0 条)org.deepin.ocr*,无 Qt 框架日志混入Summary by Sourcery
Enable categorized OCR logging with dynamically adjustable runtime log rules.
New Features:
Enhancements: