summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorhjk <hjk121@nokiamail.com>2013-09-27 13:37:37 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-06 19:47:31 +0200
commit32f27b4367c4e042a3f0cda671579494e31c1d69 (patch)
tree45b2433b6d321dd37a752b4be2cf7625ddcf5e4b /src/corelib/io
parent09a11069e7b0aafcfccad78d7f69eeb1fadd5494 (diff)
Replace QLoggingCategory::isEnabled by non-template functions
This yields the same results as previously and is more in line with existing interfaces. Change-Id: I0bf0372bf18f3bfde579385cddbe594bf71e3c52 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qloggingcategory.cpp91
-rw-r--r--src/corelib/io/qloggingcategory.h45
2 files changed, 78 insertions, 58 deletions
diff --git a/src/corelib/io/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp
index 24eeb1584c..ca9f8c1656 100644
--- a/src/corelib/io/qloggingcategory.cpp
+++ b/src/corelib/io/qloggingcategory.cpp
@@ -70,23 +70,22 @@ Q_GLOBAL_STATIC_WITH_ARGS(QLoggingCategory, qtDefaultCategory,
\section1 Checking category configuration
- QLoggingCategory provides two isEnabled methods, a template one and a
- non-template one, for checking whether the current category is enabled.
- The template version checks for the most common case that no special rules
- are applied in inline code, and should be preferred:
+ QLoggingCategory provides a generic \l isEnabled() and message
+ type dependent \l isDebugEnabled(), \l isWarningEnabled(),
+ \l isCriticalEnabled() and \l isTraceEnabled()
+ methods for checking whether the current category is enabled.
- \snippet qloggingcategory/main.cpp 2
-
- Note that qCDebug() prevents arguments from being evaluated
- if the string won't print, so calling isEnabled explicitly is not needed:
- \l isEnabled().
+ \note The qCDebug(), qCWarning(), qCCritical(), qCTrace() and
+ qCTraceGuard() macros prevent arguments from being evaluated if the
+ respective message types are not enabled for the category, so explicit
+ checking is not needed:
\snippet qloggingcategory/main.cpp 3
\section1 Default configuration
- In the default configuration \l isEnabled() will return true for all
- \l QtMsgType types except QtDebugMsg: QtDebugMsg is only active by default
+ In the default configuration \l isWarningEnabled() and \l isCriticalEnabled()
+ will return \c true. By default, \l isDebugEnabled() will return \c true only
for the \c "default" category.
\section1 Changing configuration
@@ -158,19 +157,65 @@ QLoggingCategory::~QLoggingCategory()
*/
/*!
+ \fn bool QLoggingCategory::isDebugEnabled() const
+
+ Returns \c true if debug messages should be shown for this category.
+ Returns \c false otherwise.
+
+ \note The \l qCDebug() macro already does this check before executing any
+ code. However, calling this method may be useful to avoid
+ expensive generation of data that is only used for debug output.
+*/
+
+/*!
+ \fn bool QLoggingCategory::isWarningEnabled() const
+
+ Returns \c true if warning messages should be shown for this category.
+ Returns \c false otherwise.
+
+ \note The \l qCWarning() macro already does this check before executing any
+ code. However, calling this method may be useful to avoid
+ expensive generation of data that is only used for debug output.
+*/
+
+/*!
+ \fn bool QLoggingCategory::isCriticalEnabled() const
+
+ Returns \c true if critical messages should be shown for this category.
+ Returns \c false otherwise.
+
+ \note The \l qCCritical() macro already does this check before executing any
+ code. However, calling this method may be useful to avoid
+ expensive generation of data that is only used for debug output.
+*/
+
+/*!
+ \fn bool QLoggingCategory::isTraceEnabled() const
+
+ Returns \c true if the tracers associated with this category should
+ receive messages. Returns \c false otherwise.
+
+ \note The \l qCTrace() and \l qCTraceGuard() macros already do this check
+ before executing any
+ code. However, calling this method may be useful to avoid
+ expensive generation of data that is only used for debug output.
+*/
+
+/*!
\fn bool QLoggingCategory::isEnabled() const
- Returns true if a message of the template \c QtMsgType argument should be
- shown. Returns false otherwise.
+ Returns \c true if a message of the \c QtMsgType argument should be
+ shown for this category. Returns \c false otherwise.
- \note The qCDebug, qCWarning, qCCritical macros already do this check before
- executing any code. However, calling this method may be useful to avoid
+ \note The qCDebug(), qCWarning(), qCCritical(), qCTrace() and
+ qCTraceGuard() macros already do this check before executing any code.
+ However, calling this method may be useful to avoid
expensive generation of data that is only used for debug output.
*/
/*!
- Returns true if a message of type \a msgtype for the category should be
- shown. Returns false otherwise.
+ Returns \c true if a message of type \a msgtype for the category should be
+ shown. Returns \c false otherwise.
\note The templated, inline version of this method, \l isEnabled(), is
optimized for the common case that no configuration is set, and should
@@ -195,7 +240,7 @@ bool QLoggingCategory::isEnabled(QtMsgType msgtype) const
Changes only affect the current QLoggingCategory object, and won't
change e.g. the settings of another objects for the same category name.
- \note QtFatalMsg cannot be changed. It will always return true.
+ \note QtFatalMsg cannot be changed. It will always return \c true.
Example:
@@ -291,7 +336,7 @@ void QLoggingCategory::setFilterRules(const QString &rules)
\a category.
The macro expands to code that first checks whether
- \l QLoggingCategory::isEnabled() evaluates for debug output to \c{true}.
+ \l QLoggingCategory::isDebugEnabled() evaluates to \c{true}.
If so, the stream arguments are processed and sent to the message handler.
Example:
@@ -313,7 +358,7 @@ void QLoggingCategory::setFilterRules(const QString &rules)
\a category.
The macro expands to code that first checks whether
- \l QLoggingCategory::isEnabled() evaluates for warning output to \c{true}.
+ \l QLoggingCategory::isWarningEnabled() evaluates to \c{true}.
If so, the stream arguments are processed and sent to the message handler.
Example:
@@ -335,7 +380,7 @@ void QLoggingCategory::setFilterRules(const QString &rules)
\a category.
The macro expands to code that first checks whether
- \l QLoggingCategory::isEnabled() evaluates for critical output to \c{true}.
+ \l QLoggingCategory::isCriticalEnabled() evaluates to \c{true}.
If so, the stream arguments are processed and sent to the message handler.
Example:
@@ -357,7 +402,7 @@ void QLoggingCategory::setFilterRules(const QString &rules)
\a category.
The macro expands to code that first checks whether
- \l QLoggingCategory::isEnabled() evaluates for trace output to \c{true}.
+ \l QLoggingCategory::istraceEnabled() evaluates to \c{true}.
If so, the stream arguments are processed and sent to the tracers
registered with the category.
@@ -378,7 +423,7 @@ void QLoggingCategory::setFilterRules(const QString &rules)
The macro expands to code that creates a guard object with automatic
storage. The guard constructor checks whether
- \l QLoggingCategory::isEnabled() evaluates for trace output to \c{true}.
+ \l QLoggingCategory::isTraceEnabled() evaluates to \c{true}.
If so, the stream arguments are processed and the \c{start()}
functions of the tracers registered with the \a category are called.
diff --git a/src/corelib/io/qloggingcategory.h b/src/corelib/io/qloggingcategory.h
index 70192fef13..35da04c8f2 100644
--- a/src/corelib/io/qloggingcategory.h
+++ b/src/corelib/io/qloggingcategory.h
@@ -59,15 +59,14 @@ public:
explicit QLoggingCategory(const char *category);
~QLoggingCategory();
- template <QtMsgType T>
- bool isEnabled() const
- {
- return isEnabled(T);
- }
-
bool isEnabled(QtMsgType type) const;
void setEnabled(QtMsgType type, bool enable);
+ bool isDebugEnabled() const { return enabledDebug; }
+ bool isWarningEnabled() const { return enabledWarning; }
+ bool isCriticalEnabled() const { return enabledCritical; }
+ bool isTraceEnabled() const { return enabledTrace; }
+
const char *categoryName() const { return name; }
// allows usage of both factory method and variable in qCX macros
@@ -95,30 +94,6 @@ private:
bool enabledTrace;
};
-template <>
-inline bool QLoggingCategory::isEnabled<QtDebugMsg>() const
-{
- return enabledDebug;
-}
-
-template <>
-inline bool QLoggingCategory::isEnabled<QtWarningMsg>() const
-{
- return enabledWarning;
-}
-
-template <>
-inline bool QLoggingCategory::isEnabled<QtCriticalMsg>() const
-{
- return enabledCritical;
-}
-
-template <>
-inline bool QLoggingCategory::isEnabled<QtTraceMsg>() const
-{
- return enabledTrace;
-}
-
class Q_CORE_EXPORT QTracer
{
Q_DISABLE_COPY(QTracer)
@@ -141,7 +116,7 @@ class Q_CORE_EXPORT QTraceGuard
public:
QTraceGuard(QLoggingCategory &category)
{
- target = category.isEnabled<QtTraceMsg>() ? &category : 0;
+ target = category.isTraceEnabled() ? &category : 0;
if (target)
start();
}
@@ -175,16 +150,16 @@ private:
}
#define qCDebug(category) \
- for (bool enabled = category().isEnabled<QtDebugMsg>(); enabled; enabled = false) \
+ for (bool enabled = category().isDebugEnabled(); enabled; enabled = false) \
QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category().categoryName()).debug()
#define qCWarning(category) \
- for (bool enabled = category().isEnabled<QtWarningMsg>(); enabled; enabled = false) \
+ for (bool enabled = category().isWarningEnabled(); enabled; enabled = false) \
QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category().categoryName()).warning()
#define qCCritical(category) \
- for (bool enabled = category().isEnabled<QtCriticalMsg>(); enabled; enabled = false) \
+ for (bool enabled = category().isCriticalEnabled(); enabled; enabled = false) \
QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, category().categoryName()).critical()
#define qCTrace(category) \
- for (bool enabled = category.isEnabled<QtTraceMsg>(); enabled; enabled = false) \
+ for (bool enabled = category.isTraceEnabled(); enabled; enabled = false) \
QTraceGuard(category)