From d61e7743078197f7409e863ff1d2243da7d0335f Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliokas Date: Fri, 29 Nov 2013 15:21:03 +0200 Subject: Print qCDebugs in arbitrary categories by default The debug output of all categories will be visible by default, except from the "qt.*" categories. "qt.*" categories are private and their default debug output will be hidden. [ChangeLog][QtCore][Logging] Enable qCDebug's for all categories except qt one's Change-Id: Ibe147c8bbe0835a63b3de782288b9c3251321d8f Reviewed-by: Kai Koehne --- src/corelib/io/qloggingcategory.cpp | 14 ++++----- src/corelib/io/qloggingregistry.cpp | 8 +++-- .../io/qloggingcategory/tst_qloggingcategory.cpp | 34 ++++++++++++---------- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/corelib/io/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp index 8c3ca5fd65..9ddf58b5ea 100644 --- a/src/corelib/io/qloggingcategory.cpp +++ b/src/corelib/io/qloggingcategory.cpp @@ -83,9 +83,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(QLoggingCategory, qtDefaultCategory, \section1 Default category configuration - In the default configuration \l isWarningEnabled() and \l isCriticalEnabled() - will return \c true. \l isDebugEnabled() will return \c true only - for the \c "default" category. + In the default configuration \l isWarningEnabled() , \l isDebugEnabled() and + \l isCriticalEnabled() will return \c true. \section1 Changing the configuration of a category @@ -111,21 +110,20 @@ Q_GLOBAL_STATIC_WITH_ARGS(QLoggingCategory, qtDefaultCategory, QLoggingCategory::QLoggingCategory(const char *category) : d(0), name(0), - enabledDebug(false), + enabledDebug(true), enabledWarning(true), enabledCritical(true) { Q_UNUSED(d); Q_UNUSED(placeholder); - bool isDefaultCategory + const bool isDefaultCategory = (category == 0) || (strcmp(category, qtDefaultCategoryName) == 0); + // normalize "default" category name, so that we can just do + // pointer comparison in QLoggingRegistry::updateCategory if (isDefaultCategory) { - // normalize default category names, so that we can just do - // pointer comparison in QLoggingRegistry::updateCategory name = qtDefaultCategoryName; - enabledDebug = true; } else { name = category; } diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp index a82e6f65f4..fd25ff697e 100644 --- a/src/corelib/io/qloggingregistry.cpp +++ b/src/corelib/io/qloggingregistry.cpp @@ -283,9 +283,13 @@ QLoggingRegistry *QLoggingRegistry::instance() */ void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat) { - // QLoggingCategory() normalizes all "default" strings + // QLoggingCategory() normalizes "default" strings // to qtDefaultCategoryName - bool debug = (cat->categoryName() == qtDefaultCategoryName); + bool debug = true; + char c; + if (!memcmp(cat->categoryName(), "qt", 2) && (!(c = cat->categoryName()[2]) || c == '.')) + debug = false; + bool warning = true; bool critical = true; diff --git a/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp b/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp index 26f10385b3..47a5d6044e 100644 --- a/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp +++ b/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp @@ -271,8 +271,8 @@ private slots: QCOMPARE(defaultCategory.isEnabled(QtCriticalMsg), true); QLoggingCategory customCategory("custom"); - QCOMPARE(customCategory.isDebugEnabled(), false); - QCOMPARE(customCategory.isEnabled(QtDebugMsg), false); + QCOMPARE(customCategory.isDebugEnabled(), true); + QCOMPARE(customCategory.isEnabled(QtDebugMsg), true); QCOMPARE(customCategory.isWarningEnabled(), true); QCOMPARE(customCategory.isEnabled(QtWarningMsg), true); QCOMPARE(customCategory.isCriticalEnabled(), true); @@ -309,7 +309,7 @@ private slots: QLoggingCategory cat("custom"); QCOMPARE(customCategoryFilterArgs, QStringList() << "custom"); - QVERIFY(cat.isDebugEnabled()); + QVERIFY(!cat.isDebugEnabled()); customCategoryFilterArgs.clear(); // install default filter @@ -319,7 +319,7 @@ private slots: QCOMPARE(customCategoryFilterArgs.size(), 0); QVERIFY(QLoggingCategory::defaultCategory()->isDebugEnabled()); - QVERIFY(!cat.isDebugEnabled()); + QVERIFY(cat.isDebugEnabled()); // install default filter currentFilter = @@ -328,7 +328,7 @@ private slots: QCOMPARE(customCategoryFilterArgs.size(), 0); QVERIFY(QLoggingCategory::defaultCategory()->isDebugEnabled()); - QVERIFY(!cat.isDebugEnabled()); + QVERIFY(cat.isDebugEnabled()); } void qDebugMacros() @@ -397,8 +397,12 @@ private slots: QLoggingCategory customCategory("custom"); // Check custom debug logMessage.clear(); + buf = QStringLiteral("custom.debug: Check debug with no filter active"); + qCDebug(customCategory, "Check debug with no filter active"); + QCOMPARE(logMessage, buf); + qCDebug(customCategory) << "Check debug with no filter active"; - QCOMPARE(logMessage, QString()); + QCOMPARE(logMessage, buf); // Check custom warning buf = QStringLiteral("custom.warning: Check warning with no filter active"); @@ -414,16 +418,16 @@ private slots: QLoggingCategory::installFilter(customCategoryFilter); // Check custom debug - buf = QStringLiteral("custom.debug: Check debug with filter active"); + logMessage.clear(); qCDebug(customCategory) << "Check debug with filter active"; - QCOMPARE(logMessage, buf); + QCOMPARE(logMessage, QString()); // Check different macro/category variants buf = QStringLiteral("tst.log.debug: Check debug with no filter active"); qCDebug(TST_LOG) << "Check debug with no filter active"; - QCOMPARE(logMessage, buf); + QCOMPARE(logMessage, QString()); qCDebug(TST_LOG, "Check debug with no filter active"); - QCOMPARE(logMessage, buf); + QCOMPARE(logMessage, QString()); buf = QStringLiteral("tst.log.warning: Check warning with no filter active"); qCWarning(TST_LOG) << "Check warning with no filter active"; QCOMPARE(logMessage, buf); @@ -441,8 +445,9 @@ private slots: // Check custom debug logMessage.clear(); + buf = QStringLiteral("custom.debug: Check debug with no filter active"); qCDebug(customCategory) << "Check debug with no filter active"; - QCOMPARE(logMessage, QString()); + QCOMPARE(logMessage, buf); } void checkLegacyMessageLogger() @@ -477,11 +482,11 @@ private slots: QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf)); // Check category debug - logMessage = "should not change"; - buf = logMessage; + buf = QStringLiteral("tst.log.debug: Check category Debug with no log active"); qCDebug(TST_LOG) << "Check category Debug with no log active"; QCOMPARE(logMessage, buf); + // Check default warning buf = QStringLiteral("tst.log.warning: Check category Warning with no log active"); qCWarning(TST_LOG) << "Check category Warning with no log active"; @@ -763,8 +768,7 @@ private slots: { // "" -> custom category QLoggingCategory mycategoryobject1(""); - logMessage = "no change"; - QString buf = QStringLiteral("no change"); + QString buf = QStringLiteral(".debug: My Category Object"); qCDebug(mycategoryobject1) << "My Category Object"; QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf)); -- cgit v1.2.3