summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qloggingcategory.h
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@digia.com>2014-01-09 15:38:17 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-21 14:58:03 +0100
commitb8a38a6737acd670d92197ca5b009590d9fd8a9c (patch)
tree1b01d7a85a6f35cd420e3cef1bd50490988d7058 /src/corelib/io/qloggingcategory.h
parentb152b425f74788b2f2845fb7d1a5032d86b8746d (diff)
Allow printf style for qCDebug, qCWarning, qCCritical macros
Add support for using qCDebug and friends in the 'printf style' way. This allows an almost mechanical conversion of existing qDebug, qWarning, qCritical macros, and allows avoiding the size overhead the streaming style incurs (mostly due to inlined QDebug code). To handle this gracefully we require variadic macros (part of C++11/C99). For compilers not supporting variadic macros we fall back to checking the category in QMessageLogger. [ChangeLog][QtCore][Logging] Allow qCDebug macros to be used in a printf style. Change-Id: I5a8fb135dca504e1d621bb67bf4b2a50c73d41b9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qloggingcategory.h')
-rw-r--r--src/corelib/io/qloggingcategory.h23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/corelib/io/qloggingcategory.h b/src/corelib/io/qloggingcategory.h
index 15c0519827..1e8823e92b 100644
--- a/src/corelib/io/qloggingcategory.h
+++ b/src/corelib/io/qloggingcategory.h
@@ -94,15 +94,26 @@ private:
return category; \
}
-#define qCDebug(category) \
+#ifdef Q_COMPILER_VARIADIC_MACROS
+
+#define qCDebug(category, ...) \
for (bool enabled = category().isDebugEnabled(); Q_UNLIKELY(enabled); enabled = false) \
- QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category().categoryName()).debug()
-#define qCWarning(category) \
+ QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category().categoryName()).debug(__VA_ARGS__)
+#define qCWarning(category, ...) \
for (bool enabled = category().isWarningEnabled(); enabled; enabled = false) \
- QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category().categoryName()).warning()
-#define qCCritical(category) \
+ QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category().categoryName()).warning(__VA_ARGS__)
+#define qCCritical(category, ...) \
for (bool enabled = category().isCriticalEnabled(); enabled; enabled = false) \
- QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category().categoryName()).critical()
+ QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category().categoryName()).critical(__VA_ARGS__)
+
+#else
+
+// check for enabled category inside QMessageLogger.
+#define qCDebug qDebug
+#define qCWarning qWarning
+#define qCCritical qCritical
+
+#endif // Q_COMPILER_VARIADIC_MACROS
#if defined(QT_NO_DEBUG_OUTPUT)
# undef qCDebug