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 /src/corelib/io/qloggingregistry.cpp | |
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 'src/corelib/io/qloggingregistry.cpp')
-rw-r--r-- | src/corelib/io/qloggingregistry.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp index ad15858436..dd1612c6b4 100644 --- a/src/corelib/io/qloggingregistry.cpp +++ b/src/corelib/io/qloggingregistry.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 QtCore module of the Qt Toolkit. @@ -307,12 +307,12 @@ void QLoggingRegistry::init() This method might be called concurrently for the same category object. */ -void QLoggingRegistry::registerCategory(QLoggingCategory *cat) +void QLoggingRegistry::registerCategory(QLoggingCategory *cat, QtMsgType enableForLevel) { QMutexLocker locker(®istryMutex); if (!categories.contains(cat)) { - categories.append(cat); + categories.insert(cat, enableForLevel); (*categoryFilter)(cat); } } @@ -324,8 +324,7 @@ void QLoggingRegistry::registerCategory(QLoggingCategory *cat) void QLoggingRegistry::unregisterCategory(QLoggingCategory *cat) { QMutexLocker locker(®istryMutex); - - categories.removeOne(cat); + categories.remove(cat); } /*! @@ -361,7 +360,7 @@ void QLoggingRegistry::updateRules() rules = configRules + apiRules + envRules; - foreach (QLoggingCategory *cat, categories) + foreach (QLoggingCategory *cat, categories.keys()) (*categoryFilter)(cat); } @@ -380,7 +379,7 @@ QLoggingRegistry::installFilter(QLoggingCategory::CategoryFilter filter) QLoggingCategory::CategoryFilter old = categoryFilter; categoryFilter = filter; - foreach (QLoggingCategory *cat, categories) + foreach (QLoggingCategory *cat, categories.keys()) (*categoryFilter)(cat); return old; @@ -397,18 +396,22 @@ QLoggingRegistry *QLoggingRegistry::instance() */ void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat) { - // QLoggingCategory() normalizes "default" strings - // to qtDefaultCategoryName - bool debug = true; + QLoggingRegistry *reg = QLoggingRegistry::instance(); + Q_ASSERT(reg->categories.contains(cat)); + QtMsgType enableForLevel = reg->categories.value(cat); + + bool debug = (enableForLevel == QtDebugMsg) ? true : false; + bool warning = (enableForLevel <= QtWarningMsg) ? true : false; + bool critical = (enableForLevel <= QtCriticalMsg) ? true : false; + + // hard-wired implementation of + // qt.*.debug=false + // qt.debug=false char c; if (!memcmp(cat->categoryName(), "qt", 2) && (!(c = cat->categoryName()[2]) || c == '.')) debug = false; - bool warning = true; - bool critical = true; - QString categoryName = QLatin1String(cat->categoryName()); - QLoggingRegistry *reg = QLoggingRegistry::instance(); foreach (const QLoggingRule &item, reg->rules) { int filterpass = item.pass(categoryName, QtDebugMsg); if (filterpass != 0) |