-
Notifications
You must be signed in to change notification settings - Fork 101
Loggingrules dconfig support (cherry-pick from gerrit) #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1faffb3
feat: 允许基于dtk开发的应用动态控制其日志输出等级
Whale107 6759855
fix: lshw查询内存大小时返回多元素数组,修正解析过程
0613eba
fix: 从文件中读取deepinType和productType值时因为权限问题会失败
chenjun1982 cc1c5c3
feat: 增加registerLoggingRulesWatcher接口
waterlovemelon ecff4b3
fix: 修复计算 build 版本号错误的问题
waterlovemelon 950f23f
feat: DeepinType类型增加军用版
rocet92 7c7c2bc
fix: 修复日志格式时间戳显示异常问题
Whale107 2a7c5ae
chore: loggingrules config move to preference
kegechen 58858e3
refactor: remove LoggingRules interface
kegechen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ | |
|
|
||
| #include <QtCore> | ||
| #include "LogManager.h" | ||
| #include "dconfig.h" | ||
| #include <DSGApplication> | ||
| #include <Logger.h> | ||
| #include <ConsoleAppender.h> | ||
| #include <RollingFileAppender.h> | ||
|
|
@@ -14,6 +16,7 @@ | |
|
|
||
| DCORE_BEGIN_NAMESPACE | ||
|
|
||
| #define RULES_KEY ("rules") | ||
| // Courtesy qstandardpaths_unix.cpp | ||
| static void appendOrganizationAndApp(QString &path) | ||
| { | ||
|
|
@@ -39,16 +42,79 @@ class DLogManagerPrivate { | |
| { | ||
| } | ||
|
|
||
| DConfig *createDConfig(const QString &appId); | ||
| void initLoggingRules(); | ||
| void updateLoggingRules(); | ||
|
|
||
| QString m_format; | ||
| QString m_logPath; | ||
| ConsoleAppender* m_consoleAppender = nullptr; | ||
| RollingFileAppender* m_rollingFileAppender = nullptr; | ||
| JournalAppender* m_journalAppender = nullptr; | ||
| QScopedPointer<DConfig> m_dsgConfig; | ||
| QScopedPointer<DConfig> m_fallbackConfig; | ||
|
|
||
| DLogManager *q_ptr = nullptr; | ||
| Q_DECLARE_PUBLIC(DLogManager) | ||
|
|
||
| }; | ||
|
|
||
| DConfig *DLogManagerPrivate::createDConfig(const QString &appId) | ||
| { | ||
| if (appId.isEmpty()) | ||
| return nullptr; | ||
|
|
||
| DConfig *config = DConfig::create(appId, "org.deepin.dtk.preference"); | ||
| if (!config->isValid()) { | ||
| qWarning() << "Logging rules config is invalid, please check `appId` [" << appId << "]arg is correct"; | ||
| delete config; | ||
| config = nullptr; | ||
| return nullptr; | ||
| } | ||
|
|
||
| QObject::connect(config, &DConfig::valueChanged, config, [this](const QString &key) { | ||
| if (key != RULES_KEY) | ||
| return; | ||
|
|
||
| updateLoggingRules(); | ||
| }); | ||
|
|
||
| return config; | ||
| } | ||
|
|
||
| void DLogManagerPrivate::initLoggingRules() | ||
| { | ||
| if (qEnvironmentVariableIsSet("DTK_DISABLED_LOGGING_RULES")) | ||
| return; | ||
|
|
||
| // 1. 未指定 fallbackId 时,以 dsgAppId 为准 | ||
| QString dsgAppId = DSGApplication::id(); | ||
| m_dsgConfig.reset(createDConfig(dsgAppId)); | ||
|
|
||
| QString fallbackId = qgetenv("DTK_LOGGING_FALLBACK_APPID"); | ||
| // 2. fallbackId 和 dsgAppId 非空且不等时,都创建和监听变化 | ||
| if (!fallbackId.isEmpty() && fallbackId != dsgAppId) | ||
| m_fallbackConfig.reset(createDConfig(fallbackId)); | ||
|
|
||
| // 3. 默认值和非默认值时,非默认值优先 | ||
| updateLoggingRules(); | ||
| } | ||
|
|
||
| void DLogManagerPrivate::updateLoggingRules() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在应用不重启的情况下,不能重置之前设置的值了,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 似的,reset 之后,isDefaultValue 是 true,也就是说不能用reset的方式来清空rules,只能删除的方式清空 |
||
| { | ||
| QVariant var; | ||
| // 4. 优先看 dsgConfig 是否默认值,其次 fallback 是否默认值 | ||
| if (m_dsgConfig && !m_dsgConfig->isDefaultValue(RULES_KEY)) { | ||
| var = m_dsgConfig->value(RULES_KEY); | ||
| } else if (m_fallbackConfig && !m_fallbackConfig->isDefaultValue(RULES_KEY)) { | ||
| var = m_fallbackConfig->value(RULES_KEY); | ||
| } else { | ||
| // do nothing.. | ||
| } | ||
|
|
||
| if (var.isValid()) | ||
| QLoggingCategory::setFilterRules(var.toString().replace(";", "\n")); | ||
| } | ||
| /*! | ||
| @~english | ||
| \class Dtk::Core::DLogManager | ||
|
|
@@ -62,6 +128,8 @@ DLogManager::DLogManager() | |
| { | ||
| spdlog::set_automatic_registration(true); | ||
| spdlog::set_pattern("%v"); | ||
|
|
||
| d_ptr->initLoggingRules(); | ||
| } | ||
|
|
||
| void DLogManager::initConsoleAppender(){ | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.