diff options
-rw-r--r-- | src/corelib/io/qloggingcategory.cpp | 14 | ||||
-rw-r--r-- | src/corelib/io/qloggingregistry.cpp | 10 | ||||
-rw-r--r-- | tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp | 8 |
3 files changed, 25 insertions, 7 deletions
diff --git a/src/corelib/io/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp index 7104dcdc93..08ecd67dc8 100644 --- a/src/corelib/io/qloggingcategory.cpp +++ b/src/corelib/io/qloggingcategory.cpp @@ -108,8 +108,9 @@ Q_GLOBAL_STATIC_WITH_ARGS(QLoggingCategory, qtDefaultCategory, Rules are evaluated in text order, from first to last. That is, if two rules apply to a category/type, the rule that comes later is applied. - Rules can be set via \l setFilterRules(). Since Qt 5.3 logging rules - are also automatically loaded from the \c [Rules] section of a logging + Rules can be set via \l setFilterRules(). Since Qt 5.3 logging rules can also + be set in the \c QT_LOGGING_RULES environment variable, and + are automatically loaded from the \c [Rules] section of a logging configuration file. Such configuration files are looked up in the QtProject configuration directory, or explicitly set in a \c QT_LOGGING_CONF environment variable. @@ -117,13 +118,15 @@ Q_GLOBAL_STATIC_WITH_ARGS(QLoggingCategory, qtDefaultCategory, Rules set by \l setFilterRules() take precedence over rules specified in the QtProject configuration directory, and can, in turn, be overwritten by rules from the configuration file specified by - \c QT_LOGGING_CONF. + \c QT_LOGGING_CONF, and rules set by \c QT_LOGGING_RULES. + Order of evaluation: \list \li Rules from QtProject/qlogging.ini \li Rules set by \l setFilterRules() \li Rules from file in \c QT_LOGGING_CONF + \li Rules from environment variable QT_LOGGING_RULES \endlist The \c QtProject/qlogging.ini file is looked up in all directories returned @@ -344,9 +347,8 @@ QLoggingCategory::installFilter(QLoggingCategory::CategoryFilter filter) \snippet qloggingcategory/main.cpp 2 \note The rules might be ignored if a custom category filter is installed - with \l installFilter(), or if the user defined a custom logging - configuration file in the \c QT_LOGGING_CONF environment variable. - + with \l installFilter(), or if the user defined \c QT_LOGGING_CONF or \c QT_LOGGING_RULES + environment variable. */ void QLoggingCategory::setFilterRules(const QString &rules) { diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp index 6e195d29cb..23f1ffbd16 100644 --- a/src/corelib/io/qloggingregistry.cpp +++ b/src/corelib/io/qloggingregistry.cpp @@ -248,7 +248,7 @@ static bool qtLoggingDebug() /*! \internal Initializes the rules database by loading - .config/QtProject/qtlogging.ini and $QT_LOGGING_CONF. + $QT_LOGGING_CONF, $QT_LOGGING_RULES, and .config/QtProject/qtlogging.ini. */ void QLoggingRegistry::init() { @@ -266,6 +266,14 @@ void QLoggingRegistry::init() envRules = parser.rules(); } } + const QByteArray rulesSrc = qgetenv("QT_LOGGING_RULES"); + if (!rulesSrc.isEmpty()) { + QTextStream stream(rulesSrc); + QLoggingSettingsParser parser; + parser.setSection(QStringLiteral("Rules")); + parser.setContent(stream); + envRules += parser.rules(); + } // get rules from qt configuration QString envPath = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, diff --git a/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp b/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp index ba53df03b6..4318396bd4 100644 --- a/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp +++ b/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp @@ -64,6 +64,7 @@ private slots: // ensure a clean environment QStandardPaths::setTestModeEnabled(true); qunsetenv("QT_LOGGING_CONF"); + qunsetenv("QT_LOGGING_RULES"); } void QLoggingRule_parse_data() @@ -219,6 +220,13 @@ private slots: QCOMPARE(registry.envRules.size(), 1); QCOMPARE(registry.rules.size(), 1); + + // check that QT_LOGGING_RULES take precedence + qputenv("QT_LOGGING_RULES", "Digia.*=true"); + registry.init(); + QCOMPARE(registry.envRules.size(), 2); + QCOMPARE(registry.envRules.at(1).enabled, true); + QCOMPARE(registry.rules.size(), 2); } void QLoggingRegistry_config() |