summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qloggingcategory.cpp
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@theqtcompany.com>2014-12-04 16:57:32 +0100
committerKai Koehne <kai.koehne@theqtcompany.com>2015-01-09 13:14:05 +0100
commitef6279fd516befc09d4a6b3664a727a013b82c19 (patch)
tree4365a6dfb7c8d8e3094f35eb1ffe8fb8a23088cf /src/corelib/io/qloggingcategory.cpp
parent4c980aedc17c1da8f7160989fbb845ea72b36f44 (diff)
Add QtInfoMsg
Add an 'info' message type that can be used for messages that are neither warnings (QtWarningMsg), nor for debugging only (QtDebugMsg). This is useful mainly for applications that do not have to adhere to the 'do not print anything by default' paradigm that we have for the Qt libraries itself. [ChangeLog][QtCore][Logging] QtInfoMsg got added as a new QtMsgType. Use the new qInfo(), qCInfo() macros to log to it. Change-Id: I810995d63de46c41a9a99a34d37c0d417fa87a05 Reviewed-by: Jason McDonald <macadder1@gmail.com>
Diffstat (limited to 'src/corelib/io/qloggingcategory.cpp')
-rw-r--r--src/corelib/io/qloggingcategory.cpp75
1 files changed, 67 insertions, 8 deletions
diff --git a/src/corelib/io/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp
index 79d20601a6..a032fe3d1b 100644
--- a/src/corelib/io/qloggingcategory.cpp
+++ b/src/corelib/io/qloggingcategory.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2015 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.
@@ -64,8 +64,8 @@ static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift)
QLoggingCategory represents a certain logging category - identified by a
string - at runtime. A category can be configured to enable or disable
logging of messages per message type. Whether a message type is enabled or
- not can be checked with the \l isDebugEnabled(), \l isWarningEnabled(), and
- \l isCriticalEnabled() methods.
+ not can be checked with the \l isDebugEnabled(), \l isInfoEnabled(),
+ \l isWarningEnabled(), and \l isCriticalEnabled() methods.
All objects are meant to be configured by a common registry (see also
\l{Configuring Categories}). Different objects can also represent the same
@@ -82,8 +82,8 @@ static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift)
\section1 Checking Category Configuration
- QLoggingCategory provides \l isDebugEnabled(), \l isWarningEnabled(),
- \l isCriticalEnabled(), as well as \l isEnabled()
+ QLoggingCategory provides \l isDebugEnabled(), \l isInfoEnabled(),
+ \l isWarningEnabled(), \l isCriticalEnabled(), as well as \l isEnabled()
to check whether messages for the given message type should be logged.
\note The qCDebug(), qCWarning(), qCCritical() macros prevent arguments
@@ -101,7 +101,7 @@ static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift)
\snippet qloggingcategory/main.cpp 5
will log messages of type \c QtWarningMsg, \c QtCriticalMsg, \c QtFatalMsg, but will
- ignore messages of type \c QtDebugMsg.
+ ignore messages of type \c QtDebugMsg and \c QtInfoMsg.
If no argument is passed, all messages will be logged.
@@ -122,7 +122,7 @@ static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift)
\c <category> is the name of the category, potentially with \c{*} as a
wildcard symbol as the first or last character (or at both positions).
- The optional \c <type> must be either \c debug, \c warning, or \c critical.
+ The optional \c <type> must be either \c debug, \c info, \c warning, or \c critical.
Lines that do not fit this scheme are ignored.
Rules are evaluated in text order, from first to last. That is, if two rules
@@ -250,6 +250,21 @@ QLoggingCategory::~QLoggingCategory()
expensive generation of data that is only used for debug output.
*/
+
+/*!
+ \fn bool QLoggingCategory::isInfoEnabled() const
+
+ Returns \c true if informational messages should be shown for this category.
+ Returns \c false otherwise.
+
+ \note The \l qCInfo() 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.
+
+ \since 5.5
+*/
+
+
/*!
\fn bool QLoggingCategory::isWarningEnabled() const
@@ -280,6 +295,7 @@ bool QLoggingCategory::isEnabled(QtMsgType msgtype) const
{
switch (msgtype) {
case QtDebugMsg: return isDebugEnabled();
+ case QtInfoMsg: return isInfoEnabled();
case QtWarningMsg: return isWarningEnabled();
case QtCriticalMsg: return isCriticalEnabled();
case QtFatalMsg: return true;
@@ -302,10 +318,12 @@ void QLoggingCategory::setEnabled(QtMsgType type, bool enable)
switch (type) {
#ifdef Q_ATOMIC_INT8_IS_SUPPORTED
case QtDebugMsg: bools.enabledDebug.store(enable); break;
+ case QtInfoMsg: bools.enabledInfo.store(enable); break;
case QtWarningMsg: bools.enabledWarning.store(enable); break;
case QtCriticalMsg: bools.enabledCritical.store(enable); break;
#else
case QtDebugMsg: setBoolLane(&enabled, enable, DebugShift); break;
+ case QtInfoMsg: setBoolLane(&enabled, enable, InfoShift); break;
case QtWarningMsg: setBoolLane(&enabled, enable, WarningShift); break;
case QtCriticalMsg: setBoolLane(&enabled, enable, CriticalShift); break;
#endif
@@ -331,7 +349,7 @@ void QLoggingCategory::setEnabled(QtMsgType type, bool enable)
/*!
Returns a pointer to the global category \c "default" that
- is used e.g. by qDebug(), qWarning(), qCritical(), qFatal().
+ is used e.g. by qDebug(), qInfo(), qWarning(), qCritical(), qFatal().
\note The returned pointer may be null during destruction of
static objects.
@@ -439,6 +457,47 @@ void QLoggingCategory::setFilterRules(const QString &rules)
*/
/*!
+ \macro qCInfo(category)
+ \relates QLoggingCategory
+ \since 5.5
+
+ Returns an output stream for informational messages in the logging category
+ \a category.
+
+ The macro expands to code that checks whether
+ \l QLoggingCategory::isInfoEnabled() evaluates to \c true.
+ If so, the stream arguments are processed and sent to the message handler.
+
+ Example:
+
+ \snippet qloggingcategory/main.cpp qcinfo_stream
+
+ \note Arguments are not processed if debug output for the category is not
+ enabled, so do not rely on any side effects.
+
+ \sa qInfo()
+*/
+
+/*!
+ \macro qCInfo(category, const char *message, ...)
+ \relates QLoggingCategory
+ \since 5.5
+
+ Logs an informational message \a message in the logging category \a category.
+ \a message might contain place holders that are replaced by additional
+ arguments, similar to the C printf() function.
+
+ Example:
+
+ \snippet qloggingcategory/main.cpp qcinfo_printf
+
+ \note Arguments might not be processed if debug output for the category is
+ not enabled, so do not rely on any side effects.
+
+ \sa qInfo()
+*/
+
+/*!
\macro qCWarning(category)
\relates QLoggingCategory
\since 5.2