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/qloggingcategory.h | |
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/qloggingcategory.h')
-rw-r--r-- | src/corelib/io/qloggingcategory.h | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/corelib/io/qloggingcategory.h b/src/corelib/io/qloggingcategory.h index 2025911e2c..cca2031108 100644 --- a/src/corelib/io/qloggingcategory.h +++ b/src/corelib/io/qloggingcategory.h @@ -51,7 +51,9 @@ class Q_CORE_EXPORT QLoggingCategory { Q_DISABLE_COPY(QLoggingCategory) public: + // ### Qt 6: Merge constructors explicit QLoggingCategory(const char *category); + QLoggingCategory(const char *category, QtMsgType severityLevel); ~QLoggingCategory(); bool isEnabled(QtMsgType type) const; @@ -80,6 +82,8 @@ public: static void setFilterRules(const QString &rules); private: + void init(const char *category, QtMsgType severityLevel); + Q_DECL_UNUSED_MEMBER void *d; // reserved for future use const char *name; @@ -106,16 +110,14 @@ private: #define Q_DECLARE_LOGGING_CATEGORY(name) \ extern const QLoggingCategory &name(); -// relies on QLoggingCategory(QString) being thread safe! -#define Q_LOGGING_CATEGORY(name, string) \ +#if defined(Q_COMPILER_VARIADIC_MACROS) || defined(Q_MOC_RUN) + +#define Q_LOGGING_CATEGORY(name, ...) \ const QLoggingCategory &name() \ { \ - static const QLoggingCategory category(string); \ + static const QLoggingCategory category(__VA_ARGS__); \ return category; \ } - -#ifdef Q_COMPILER_VARIADIC_MACROS - #define qCDebug(category, ...) \ for (bool qt_category_enabled = category().isDebugEnabled(); qt_category_enabled; qt_category_enabled = false) \ QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category().categoryName()).debug(__VA_ARGS__) @@ -126,14 +128,22 @@ private: for (bool qt_category_enabled = category().isCriticalEnabled(); qt_category_enabled; qt_category_enabled = false) \ QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category().categoryName()).critical(__VA_ARGS__) -#else +#else // defined(Q_COMPILER_VARIADIC_MACROS) || defined(Q_MOC_RUN) + +// Optional msgType argument not supported +#define Q_LOGGING_CATEGORY(name, string) \ + const QLoggingCategory &name() \ + { \ + static const QLoggingCategory category(string); \ + return category; \ + } // check for enabled category inside QMessageLogger. #define qCDebug qDebug #define qCWarning qWarning #define qCCritical qCritical -#endif // Q_COMPILER_VARIADIC_MACROS +#endif // Q_COMPILER_VARIADIC_MACROS || defined(Q_MOC_RUN) #if defined(QT_NO_DEBUG_OUTPUT) # undef qCDebug |