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 <kai.koehne@digia.com>
This commit is contained in:
Giorgos Tsiapaliokas 2013-11-29 15:21:03 +02:00 committed by The Qt Project
parent 3d08681169
commit d61e774307
3 changed files with 31 additions and 25 deletions

View File

@ -83,9 +83,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(QLoggingCategory, qtDefaultCategory,
\section1 Default category configuration \section1 Default category configuration
In the default configuration \l isWarningEnabled() and \l isCriticalEnabled() In the default configuration \l isWarningEnabled() , \l isDebugEnabled() and
will return \c true. \l isDebugEnabled() will return \c true only \l isCriticalEnabled() will return \c true.
for the \c "default" category.
\section1 Changing the configuration of a category \section1 Changing the configuration of a category
@ -111,21 +110,20 @@ Q_GLOBAL_STATIC_WITH_ARGS(QLoggingCategory, qtDefaultCategory,
QLoggingCategory::QLoggingCategory(const char *category) QLoggingCategory::QLoggingCategory(const char *category)
: d(0), : d(0),
name(0), name(0),
enabledDebug(false), enabledDebug(true),
enabledWarning(true), enabledWarning(true),
enabledCritical(true) enabledCritical(true)
{ {
Q_UNUSED(d); Q_UNUSED(d);
Q_UNUSED(placeholder); Q_UNUSED(placeholder);
bool isDefaultCategory const bool isDefaultCategory
= (category == 0) || (strcmp(category, qtDefaultCategoryName) == 0); = (category == 0) || (strcmp(category, qtDefaultCategoryName) == 0);
// normalize "default" category name, so that we can just do
// pointer comparison in QLoggingRegistry::updateCategory
if (isDefaultCategory) { if (isDefaultCategory) {
// normalize default category names, so that we can just do
// pointer comparison in QLoggingRegistry::updateCategory
name = qtDefaultCategoryName; name = qtDefaultCategoryName;
enabledDebug = true;
} else { } else {
name = category; name = category;
} }

View File

@ -283,9 +283,13 @@ QLoggingRegistry *QLoggingRegistry::instance()
*/ */
void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat) void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat)
{ {
// QLoggingCategory() normalizes all "default" strings // QLoggingCategory() normalizes "default" strings
// to qtDefaultCategoryName // 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 warning = true;
bool critical = true; bool critical = true;

View File

@ -271,8 +271,8 @@ private slots:
QCOMPARE(defaultCategory.isEnabled(QtCriticalMsg), true); QCOMPARE(defaultCategory.isEnabled(QtCriticalMsg), true);
QLoggingCategory customCategory("custom"); QLoggingCategory customCategory("custom");
QCOMPARE(customCategory.isDebugEnabled(), false); QCOMPARE(customCategory.isDebugEnabled(), true);
QCOMPARE(customCategory.isEnabled(QtDebugMsg), false); QCOMPARE(customCategory.isEnabled(QtDebugMsg), true);
QCOMPARE(customCategory.isWarningEnabled(), true); QCOMPARE(customCategory.isWarningEnabled(), true);
QCOMPARE(customCategory.isEnabled(QtWarningMsg), true); QCOMPARE(customCategory.isEnabled(QtWarningMsg), true);
QCOMPARE(customCategory.isCriticalEnabled(), true); QCOMPARE(customCategory.isCriticalEnabled(), true);
@ -309,7 +309,7 @@ private slots:
QLoggingCategory cat("custom"); QLoggingCategory cat("custom");
QCOMPARE(customCategoryFilterArgs, QStringList() << "custom"); QCOMPARE(customCategoryFilterArgs, QStringList() << "custom");
QVERIFY(cat.isDebugEnabled()); QVERIFY(!cat.isDebugEnabled());
customCategoryFilterArgs.clear(); customCategoryFilterArgs.clear();
// install default filter // install default filter
@ -319,7 +319,7 @@ private slots:
QCOMPARE(customCategoryFilterArgs.size(), 0); QCOMPARE(customCategoryFilterArgs.size(), 0);
QVERIFY(QLoggingCategory::defaultCategory()->isDebugEnabled()); QVERIFY(QLoggingCategory::defaultCategory()->isDebugEnabled());
QVERIFY(!cat.isDebugEnabled()); QVERIFY(cat.isDebugEnabled());
// install default filter // install default filter
currentFilter = currentFilter =
@ -328,7 +328,7 @@ private slots:
QCOMPARE(customCategoryFilterArgs.size(), 0); QCOMPARE(customCategoryFilterArgs.size(), 0);
QVERIFY(QLoggingCategory::defaultCategory()->isDebugEnabled()); QVERIFY(QLoggingCategory::defaultCategory()->isDebugEnabled());
QVERIFY(!cat.isDebugEnabled()); QVERIFY(cat.isDebugEnabled());
} }
void qDebugMacros() void qDebugMacros()
@ -397,8 +397,12 @@ private slots:
QLoggingCategory customCategory("custom"); QLoggingCategory customCategory("custom");
// Check custom debug // Check custom debug
logMessage.clear(); 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"; qCDebug(customCategory) << "Check debug with no filter active";
QCOMPARE(logMessage, QString()); QCOMPARE(logMessage, buf);
// Check custom warning // Check custom warning
buf = QStringLiteral("custom.warning: Check warning with no filter active"); buf = QStringLiteral("custom.warning: Check warning with no filter active");
@ -414,16 +418,16 @@ private slots:
QLoggingCategory::installFilter(customCategoryFilter); QLoggingCategory::installFilter(customCategoryFilter);
// Check custom debug // Check custom debug
buf = QStringLiteral("custom.debug: Check debug with filter active"); logMessage.clear();
qCDebug(customCategory) << "Check debug with filter active"; qCDebug(customCategory) << "Check debug with filter active";
QCOMPARE(logMessage, buf); QCOMPARE(logMessage, QString());
// Check different macro/category variants // Check different macro/category variants
buf = QStringLiteral("tst.log.debug: Check debug with no filter active"); buf = QStringLiteral("tst.log.debug: Check debug with no filter active");
qCDebug(TST_LOG) << "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"); 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"); buf = QStringLiteral("tst.log.warning: Check warning with no filter active");
qCWarning(TST_LOG) << "Check warning with no filter active"; qCWarning(TST_LOG) << "Check warning with no filter active";
QCOMPARE(logMessage, buf); QCOMPARE(logMessage, buf);
@ -441,8 +445,9 @@ private slots:
// Check custom debug // Check custom debug
logMessage.clear(); logMessage.clear();
buf = QStringLiteral("custom.debug: Check debug with no filter active");
qCDebug(customCategory) << "Check debug with no filter active"; qCDebug(customCategory) << "Check debug with no filter active";
QCOMPARE(logMessage, QString()); QCOMPARE(logMessage, buf);
} }
void checkLegacyMessageLogger() void checkLegacyMessageLogger()
@ -477,11 +482,11 @@ private slots:
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf)); QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
// Check category debug // Check category debug
logMessage = "should not change"; buf = QStringLiteral("tst.log.debug: Check category Debug with no log active");
buf = logMessage;
qCDebug(TST_LOG) << "Check category Debug with no log active"; qCDebug(TST_LOG) << "Check category Debug with no log active";
QCOMPARE(logMessage, buf); QCOMPARE(logMessage, buf);
// Check default warning // Check default warning
buf = QStringLiteral("tst.log.warning: Check category Warning with no log active"); buf = QStringLiteral("tst.log.warning: Check category Warning with no log active");
qCWarning(TST_LOG) << "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 // "" -> custom category
QLoggingCategory mycategoryobject1(""); QLoggingCategory mycategoryobject1("");
logMessage = "no change"; QString buf = QStringLiteral(".debug: My Category Object");
QString buf = QStringLiteral("no change");
qCDebug(mycategoryobject1) << "My Category Object"; qCDebug(mycategoryobject1) << "My Category Object";
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf)); QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));