Skip to content

Commit

Permalink
chore: loggingrules config move to preference
Browse files Browse the repository at this point in the history
org.deepin.dtk.logginerules ==> org.deepin.dtk.preference
如果 DConfig 无效就不清空环境变量
  • Loading branch information
kegechen committed May 14, 2024
1 parent 711270d commit 06c34a9
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/log/LogManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,8 @@ void DLogManager::initLoggingRules(const QString &appId)
return;
}

// QT_LOGGING_RULES环境变量设置日志的优先级最高
// QLoggingRegistry 初始化时会获取 QT_LOGGING_RULES 的值并保存,后续重置了环境变量 QLoggingRegistry 不会进行同步
// 需要在 QLoggingRegistry 初始化之前重置 QT_LOGGING_RULES 的值
QByteArray logRules = qgetenv("QT_LOGGING_RULES");
qunsetenv("QT_LOGGING_RULES");

if (!logRules.isEmpty()) {
QLoggingCategory::setFilterRules(logRules.replace(";", "\n"));
}

Q_D(DLogManager);
d->m_loggingRulesConfig = DConfig::create(appId, "org.deepin.dtk.loggingrules");
d->m_loggingRulesConfig = DConfig::create(appId, "org.deepin.dtk.preference");
if (!d->m_loggingRulesConfig) {
qWarning() << "Create logging rules dconfig object failed, logging rules won't take effect";
return;
Expand All @@ -157,6 +147,16 @@ void DLogManager::initLoggingRules(const QString &appId)
return;
}

// QT_LOGGING_RULES环境变量设置日志的优先级最高
// QLoggingRegistry 初始化时会获取 QT_LOGGING_RULES 的值并保存,后续重置了环境变量 QLoggingRegistry 不会进行同步
// 需要在 QLoggingRegistry 初始化之前重置 QT_LOGGING_RULES 的值
QByteArray logRules = qgetenv("QT_LOGGING_RULES");
qunsetenv("QT_LOGGING_RULES");

if (!logRules.isEmpty()) {
QLoggingCategory::setFilterRules(logRules.replace(";", "\n"));
}

auto updateLoggingRules = [d](const QString & key) {
if (key != RULES_KEY)
return;
Expand Down

0 comments on commit 06c34a9

Please sign in to comment.