fix(logging): add Qt logging filter rules initialization#475
Open
add-uos wants to merge 1 commit into
Open
Conversation
Add initLoggingRules() to read QT_LOGGING_RULES environment variable for log filtering. Default to disabling debug logs when unset. 添加 Qt 日志过滤规则初始化,通过 QT_LOGGING_RULES 环境变量控制日志输出, 未设置时默认关闭 debug 日志。 Log: 添加 Qt 日志过滤规则初始化功能 PMS: https://pms.uniontech.com/bug-view-348319.html Influence: 应用启动时可通过环境变量控制日志级别,默认关闭 debug 日志减少输出噪音。
5c531ec to
56ac722
Compare
deepin pr auto review你好!我是CodeGeeX,你的智能编程助手。我已仔细审查了你提供的 Git Diff 代码。 这段代码的主要目的是在应用程序启动时初始化 Qt 的日志过滤规则,默认关闭所有 以下是我从语法逻辑、代码质量、代码性能和代码安全四个维度提出的审查意见和改进建议: 1. 语法与逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进后的代码建议结合上述分析,我为你提供一份改进后的代码参考: #include <QDebug>
#include <iostream>
#include <QLoggingCategory>
#include <QCoreApplication> // 确保包含了对应的头文件
DWIDGET_USE_NAMESPACE
// 使用 constexpr 替代 C 风格的 const char*
static constexpr const char* DEFAULT_LOGGING_RULES = "*.debug=false";
static void initLoggingRules()
{
QByteArray rules = qgetenv("QT_LOGGING_RULES");
if (rules.isEmpty()) {
QLoggingCategory::setFilterRules(DEFAULT_LOGGING_RULES);
} else {
// 如果设置了环境变量,可以选择在启动时打印一下,方便调试
// 注意:这里用 qCInfo 或者不打印,因为 qDebug 可能已被环境变量屏蔽
}
}
int main(int argc, char *argv[])
{
// 1. 创建 QCoreApplication 实例 (假设原代码中有)
QCoreApplication app(argc, argv);
// 2. 初始化日志规则
initLoggingRules();
// 3. 修复逻辑冲突:将 qDebug 改为 qInfo,确保默认情况下也能看到启动参数
// 安全提示:请确保 QCoreApplication::arguments() 中不包含敏感信息(如密码)
qInfo() << "Application starting with arguments:" << QCoreApplication::arguments();
DCORE_USE_NAMESPACE
PerformanceMonitor::initializeAppStart();
// ... 其他代码
return app.exec();
}主要改动点说明:
|
lzwind
approved these changes
Jun 10, 2026
|
[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 |
Contributor
|
TAG Bot New tag: 6.5.55 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add initLoggingRules() to read QT_LOGGING_RULES environment variable for log filtering. Default to disabling debug logs when unset.
添加 Qt 日志过滤规则初始化,通过 QT_LOGGING_RULES 环境变量控制日志输出,
未设置时默认关闭 debug 日志。
Log: 添加 Qt 日志过滤规则初始化功能
PMS: https://pms.uniontech.com/bug-view-348319.html
Influence: 应用启动时可通过环境变量控制日志级别,默认关闭 debug 日志减少输出噪音。