diff options
author | Kai Koehne <kai.koehne@digia.com> | 2014-07-11 12:36:30 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@digia.com> | 2014-07-23 15:38:10 +0200 |
commit | ea34893b8ff4374fb631da19101ea5ea998eb9dc (patch) | |
tree | 40f5ed901a24d6f80639ad47b4b67794c6ab5cb8 /tests/auto/corelib/io/qloggingcategory | |
parent | c4a2d6ca1ea3e1411391978f089c0b360c833f1b (diff) |
Support setting a default severity level for QLoggingCategory
Allow to alter the default configuration for categories by passing a
message type: All message types with lower severity are disabled in this
category.
This is useful for libraries, which shouldn't mess with the category
registry itself: Setting rules, a category filter ... might cause
conflicts and ordering problems, so this API should be reserved to the
specific application.
For the Qt categories, we have code in the default category filter that
disables the 'debug' category. However, this is hardcoded, and there's no
way so far for other libraries to get the same behavior. With this patch
one can get the same behavior:
Q_LOGGING_CATEGORY(DRIVER_USB_EVENTS, "driver.usb.events", QtWarningMsg);
[ChangeLog][QtCore][Logging] Added QtMsgType argument to QLoggingCategory
constructor and Q_LOGGING_CATEGORY macro that controls the default
category configuration.
Change-Id: Ib2902f755f9f7285d79888ec30e8f3cef95ae628
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'tests/auto/corelib/io/qloggingcategory')
-rw-r--r-- | tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp b/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp index b0d7a76f0f..6d49238e51 100644 --- a/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp +++ b/tests/auto/corelib/io/qloggingcategory/tst_qloggingcategory.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -44,7 +44,6 @@ #include <QLoggingCategory> Q_LOGGING_CATEGORY(TST_LOG, "tst.log") -Q_LOGGING_CATEGORY(TST_LOG1, "tst.log1") Q_LOGGING_CATEGORY(Digia_Oslo_Office_com, "Digia.Oslo.Office.com") Q_LOGGING_CATEGORY(Digia_Oulu_Office_com, "Digia.Oulu.Office.com") Q_LOGGING_CATEGORY(Digia_Berlin_Office_com, "Digia.Berlin.Office.com") @@ -278,6 +277,14 @@ private slots: QCOMPARE(customCategory.isCriticalEnabled(), true); QCOMPARE(customCategory.isEnabled(QtCriticalMsg), true); + QLoggingCategory onlyWarningsCategory("withType", QtWarningMsg); + QCOMPARE(onlyWarningsCategory.isDebugEnabled(), false); + QCOMPARE(onlyWarningsCategory.isEnabled(QtDebugMsg), false); + QCOMPARE(onlyWarningsCategory.isWarningEnabled(), true); + QCOMPARE(onlyWarningsCategory.isEnabled(QtWarningMsg), true); + QCOMPARE(onlyWarningsCategory.isCriticalEnabled(), true); + QCOMPARE(onlyWarningsCategory.isEnabled(QtCriticalMsg), true); + // make sure nothing has printed warnings QVERIFY(logMessage.isEmpty()); } @@ -367,6 +374,35 @@ private slots: QCOMPARE(logMessage, buf); } + Q_LOGGING_CATEGORY(TST_MACRO_1, "tst.macro.1") +#ifdef Q_COMPILER_VARIADIC_MACROS + Q_LOGGING_CATEGORY(TST_MACRO_2, "tst.macro.2", QtDebugMsg) + Q_LOGGING_CATEGORY(TST_MACRO_3, "tst.macro.3", QtFatalMsg) +#endif + + void QLoggingCategoryMacro() + { + const QLoggingCategory &cat1 = TST_MACRO_1(); + QCOMPARE(cat1.categoryName(), "tst.macro.1"); + QCOMPARE(cat1.isDebugEnabled(), true); + QCOMPARE(cat1.isWarningEnabled(), true); + QCOMPARE(cat1.isCriticalEnabled(), true); + +#ifdef Q_COMPILER_VARIADIC_MACROS + const QLoggingCategory &cat2 = TST_MACRO_2(); + QCOMPARE(cat2.categoryName(), "tst.macro.2"); + QCOMPARE(cat2.isDebugEnabled(), true); + QCOMPARE(cat2.isWarningEnabled(), true); + QCOMPARE(cat2.isCriticalEnabled(), true); + + const QLoggingCategory &cat3 = TST_MACRO_3(); + QCOMPARE(cat3.categoryName(), "tst.macro.3"); + QCOMPARE(cat3.isDebugEnabled(), false); + QCOMPARE(cat3.isWarningEnabled(), false); + QCOMPARE(cat3.isCriticalEnabled(), false); +#endif + } + void qCDebugMacros() { QString buf; |