Initialize QLoggingRegistry rules on first use, not qApp construction
Allows categorized logging before QCoreApplication has been created, which otherwise would silently fail to output anything because the category would never be enabled, despite QT_LOGGING_RULES being set. Change-Id: Ia733105c5b6f28e22af511ced5271e45782da12b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
9595622e36
commit
47cc9e23a3
@ -255,6 +255,7 @@ void QLoggingSettingsParser::parseNextLine(QStringRef line)
|
||||
QLoggingRegistry::QLoggingRegistry()
|
||||
: categoryFilter(defaultCategoryFilter)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
static bool qtLoggingDebug()
|
||||
|
@ -113,8 +113,6 @@ class Q_AUTOTEST_EXPORT QLoggingRegistry
|
||||
public:
|
||||
QLoggingRegistry();
|
||||
|
||||
void init();
|
||||
|
||||
void registerCategory(QLoggingCategory *category, QtMsgType enableForLevel);
|
||||
void unregisterCategory(QLoggingCategory *category);
|
||||
|
||||
@ -126,6 +124,7 @@ public:
|
||||
static QLoggingRegistry *instance();
|
||||
|
||||
private:
|
||||
void init();
|
||||
void updateRules();
|
||||
|
||||
static void defaultCategoryFilter(QLoggingCategory *category);
|
||||
|
@ -771,8 +771,6 @@ void QCoreApplicationPrivate::init()
|
||||
if (!coreappdata()->applicationVersionSet)
|
||||
coreappdata()->applicationVersion = appVersion();
|
||||
|
||||
QLoggingRegistry::instance()->init();
|
||||
|
||||
#if QT_CONFIG(library)
|
||||
// Reset the lib paths, so that they will be recomputed, taking the availability of argv[0]
|
||||
// into account. If necessary, recompute right away and replay the manual changes on top of the
|
||||
|
@ -197,9 +197,23 @@ private slots:
|
||||
// Check whether QT_LOGGING_CONF is picked up from environment
|
||||
//
|
||||
|
||||
qputenv("QT_LOGGING_CONF", QFINDTESTDATA("qtlogging.ini").toLocal8Bit());
|
||||
Q_ASSERT(!qApp);
|
||||
|
||||
qputenv("QT_LOGGING_RULES", "qt.foo.bar=true");
|
||||
|
||||
QLoggingRegistry registry;
|
||||
QCOMPARE(registry.apiRules.size(), 0);
|
||||
QCOMPARE(registry.configRules.size(), 0);
|
||||
QCOMPARE(registry.envRules.size(), 1);
|
||||
QCOMPARE(registry.rules.size(), 1);
|
||||
|
||||
QLoggingCategory qtEnabledByLoggingRule("qt.foo.bar");
|
||||
QCOMPARE(qtEnabledByLoggingRule.isDebugEnabled(), true);
|
||||
QLoggingCategory qtDisabledByDefault("qt.foo.baz");
|
||||
QCOMPARE(qtDisabledByDefault.isDebugEnabled(), false);
|
||||
|
||||
qunsetenv("QT_LOGGING_RULES");
|
||||
qputenv("QT_LOGGING_CONF", QFINDTESTDATA("qtlogging.ini").toLocal8Bit());
|
||||
registry.init();
|
||||
|
||||
QCOMPARE(registry.apiRules.size(), 0);
|
||||
@ -304,6 +318,6 @@ private slots:
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(tst_QLoggingRegistry)
|
||||
QTEST_APPLESS_MAIN(tst_QLoggingRegistry)
|
||||
|
||||
#include "tst_qloggingregistry.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user