summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
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/global
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/global')
-rw-r--r--src/corelib/global/qglobal.cpp66
-rw-r--r--src/corelib/global/qlogging.cpp149
-rw-r--r--src/corelib/global/qlogging.h15
3 files changed, 209 insertions, 21 deletions
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 5206a038c8..e817b05243 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.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).
** Copyright (C) 2014 Intel Corporation
** Contact: http://www.qt-project.org/legal
**
@@ -547,9 +547,9 @@ Q_STATIC_ASSERT_X(UCHAR_MAX == 255, "Qt assumes that char is 8 bits");
\snippet code/src_corelib_global_qglobal.cpp 3
<QtGlobal> also contains functions that generate messages from the
- given string argument: qCritical(), qDebug(), qFatal() and
- qWarning(). These functions call the message handler with the
- given message.
+ given string argument: qDebug(), qInfo(), qWarning(), qCritical(),
+ and qFatal(). These functions call the message handler
+ with the given message.
Example:
@@ -768,6 +768,8 @@ Q_STATIC_ASSERT_X(UCHAR_MAX == 255, "Qt assumes that char is 8 bits");
\value QtDebugMsg
A message generated by the qDebug() function.
+ \value QtInfoMsg
+ A message generated by the qInfo() function.
\value QtWarningMsg
A message generated by the qWarning() function.
\value QtCriticalMsg
@@ -776,6 +778,7 @@ Q_STATIC_ASSERT_X(UCHAR_MAX == 255, "Qt assumes that char is 8 bits");
A message generated by the qFatal() function.
\value QtSystemMsg
+ \c QtInfoMsg was added in Qt 5.5.
\sa QtMessageHandler, qInstallMessageHandler()
*/
@@ -3539,8 +3542,8 @@ int qrand()
qPrintable() is used. This is because the array returned by
QString::toLocal8Bit() will fall out of scope.
- \note qDebug(), qWarning(), qCritical(), qFatal() expect %s
- arguments to be UTF-8 encoded, while qPrintable() converts to
+ \note qDebug(), qInfo(), qWarning(), qCritical(), qFatal() expect
+ %s arguments to be UTF-8 encoded, while qPrintable() converts to
local 8-bit encoding. Therefore qUtf8Printable() should be used
for logging strings instead of qPrintable().
@@ -3563,7 +3566,7 @@ int qrand()
\snippet code/src_corelib_global_qglobal.cpp 37
- \sa qPrintable(), qDebug(), qWarning(), qCritical(), qFatal()
+ \sa qPrintable(), qDebug(), qInfo(), qWarning(), qCritical(), qFatal()
*/
/*!
@@ -3974,8 +3977,8 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
Calls the message handler with the debug message \a message. If no
message handler has been installed, the message is printed to
- stderr. Under Windows, the message is sent to the console, if it is a
- console application; otherwise, it is sent to the debugger. On Blackberry the
+ stderr. Under Windows the message is sent to the console, if it is a
+ console application; otherwise, it is sent to the debugger. On Blackberry, the
message is sent to slogger2. This function does nothing if \c QT_NO_DEBUG_OUTPUT
was defined during compilation.
@@ -4000,7 +4003,44 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
To suppress the output at run-time, install your own message handler
with qInstallMessageHandler().
- \sa qWarning(), qCritical(), qFatal(), qInstallMessageHandler(),
+ \sa qInfo(), qWarning(), qCritical(), qFatal(), qInstallMessageHandler(),
+ {Debugging Techniques}
+*/
+
+/*!
+ \macro qInfo(const char *message, ...)
+ \relates <QtGlobal>
+ \since 5.5
+
+ Calls the message handler with the informational message \a message. If no
+ message handler has been installed, the message is printed to
+ stderr. Under Windows, the message is sent to the console, if it is a
+ console application; otherwise, it is sent to the debugger. On Blackberry the
+ message is sent to slogger2. This function does nothing if \c QT_NO_INFO_OUTPUT
+ was defined during compilation.
+
+ If you pass the function a format string and a list of arguments,
+ it works in similar way to the C printf() function. The format
+ should be a Latin-1 string.
+
+ Example:
+
+ \snippet code/src_corelib_global_qglobal.cpp qInfo_printf
+
+ If you include \c <QtDebug>, a more convenient syntax is also
+ available:
+
+ \snippet code/src_corelib_global_qglobal.cpp qInfo_stream
+
+ With this syntax, the function returns a QDebug object that is
+ configured to use the QtInfoMsg message type. It automatically
+ puts a single space between each item, and outputs a newline at
+ the end. It supports many C++ and Qt types.
+
+ To suppress the output at run-time, install your own message handler
+ with qInstallMessageHandler().
+
+ \sa qDebug(), qWarning(), qCritical(), qFatal(), qInstallMessageHandler(),
{Debugging Techniques}
*/
@@ -4034,7 +4074,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
To suppress the output at runtime, install your own message handler
with qInstallMessageHandler().
- \sa qDebug(), qCritical(), qFatal(), qInstallMessageHandler(),
+ \sa qDebug(), qInfo(), qCritical(), qFatal(), qInstallMessageHandler(),
{Debugging Techniques}
*/
@@ -4067,7 +4107,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
To suppress the output at runtime, install your own message handler
with qInstallMessageHandler().
- \sa qDebug(), qWarning(), qFatal(), qInstallMessageHandler(),
+ \sa qDebug(), qInfo(), qWarning(), qFatal(), qInstallMessageHandler(),
{Debugging Techniques}
*/
@@ -4094,7 +4134,7 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
To suppress the output at runtime, install your own message handler
with qInstallMessageHandler().
- \sa qDebug(), qCritical(), qWarning(), qInstallMessageHandler(),
+ \sa qDebug(), qInfo(), qWarning(), qCritical(), qInstallMessageHandler(),
{Debugging Techniques}
*/
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index 66829752f9..6c545bb65f 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.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).
** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com>
** Copyright (C) 2014 Intel Corporation.
** Contact: http://www.qt-project.org/legal
@@ -201,7 +201,7 @@ Q_CORE_EXPORT bool qt_logging_to_console()
\brief The QMessageLogContext class provides additional information about a log message.
\since 5.0
- The class provides information about the source code location a qDebug(), qWarning(),
+ The class provides information about the source code location a qDebug(), qInfo(), qWarning(),
qCritical() or qFatal() message was generated.
\note By default, this information is recorded only in debug builds. You can overwrite
@@ -217,7 +217,7 @@ Q_CORE_EXPORT bool qt_logging_to_console()
\since 5.0
QMessageLogger is used to generate messages for the Qt logging framework. Usually one uses
- it through qDebug(), qWarning(), qCritical, or qFatal() functions,
+ it through qDebug(), qInfo(), qWarning(), qCritical, or qFatal() functions,
which are actually macros: For example qDebug() expands to
QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debug()
for debug builds, and QMessageLogger(0, 0, 0).debug() for release builds.
@@ -226,7 +226,7 @@ Q_CORE_EXPORT bool qt_logging_to_console()
\snippet code/qlogging/qlogging.cpp 1
- \sa QMessageLogContext, qDebug(), qWarning(), qCritical(), qFatal()
+ \sa QMessageLogContext, qDebug(), qInfo(), qWarning(), qCritical(), qFatal()
*/
#ifdef Q_OS_WIN
@@ -277,6 +277,28 @@ void QMessageLogger::debug(const char *msg, ...) const
qt_message_fatal(QtDebugMsg, context, message);
}
+
+#undef qInfo
+/*!
+ Logs an informational message specified with format \a msg. Additional
+ parameters, specified by \a msg, may be used.
+
+ \sa qInfo()
+ \since 5.5
+*/
+void QMessageLogger::info(const char *msg, ...) const
+{
+ QString message;
+
+ va_list ap;
+ va_start(ap, msg); // use variable arg list
+ qt_message(QtInfoMsg, context, msg, ap, message);
+ va_end(ap);
+
+ if (isFatal(QtInfoMsg))
+ qt_message_fatal(QtInfoMsg, context, message);
+}
+
/*!
\typedef QMessageLogger::CategoryFunction
@@ -406,6 +428,110 @@ QNoDebug QMessageLogger::noDebug() const Q_DECL_NOTHROW
#endif
+/*!
+ Logs an informational message specified with format \a msg for the context \a cat.
+ Additional parameters, specified by \a msg, may be used.
+
+ \since 5.5
+ \sa qCInfo()
+*/
+void QMessageLogger::info(const QLoggingCategory &cat, const char *msg, ...) const
+{
+ if (!cat.isInfoEnabled())
+ return;
+
+ QMessageLogContext ctxt;
+ ctxt.copy(context);
+ ctxt.category = cat.categoryName();
+
+ QString message;
+
+ va_list ap;
+ va_start(ap, msg); // use variable arg list
+ qt_message(QtInfoMsg, ctxt, msg, ap, message);
+ va_end(ap);
+
+ if (isFatal(QtInfoMsg))
+ qt_message_fatal(QtInfoMsg, ctxt, message);
+}
+
+/*!
+ Logs an informational message specified with format \a msg for the context returned
+ by \a catFunc. Additional parameters, specified by \a msg, may be used.
+
+ \since 5.5
+ \sa qCInfo()
+*/
+void QMessageLogger::info(QMessageLogger::CategoryFunction catFunc,
+ const char *msg, ...) const
+{
+ const QLoggingCategory &cat = (*catFunc)();
+ if (!cat.isInfoEnabled())
+ return;
+
+ QMessageLogContext ctxt;
+ ctxt.copy(context);
+ ctxt.category = cat.categoryName();
+
+ QString message;
+
+ va_list ap;
+ va_start(ap, msg); // use variable arg list
+ qt_message(QtInfoMsg, ctxt, msg, ap, message);
+ va_end(ap);
+
+ if (isFatal(QtInfoMsg))
+ qt_message_fatal(QtInfoMsg, ctxt, message);
+}
+
+#ifndef QT_NO_DEBUG_STREAM
+
+/*!
+ Logs an informational message using a QDebug stream.
+
+ \since 5.5
+ \sa qInfo(), QDebug
+*/
+QDebug QMessageLogger::info() const
+{
+ QDebug dbg = QDebug(QtInfoMsg);
+ QMessageLogContext &ctxt = dbg.stream->context;
+ ctxt.copy(context);
+ return dbg;
+}
+
+/*!
+ Logs an informational message into the category \a cat using a QDebug stream.
+
+ \since 5.5
+ \sa qCInfo(), QDebug
+*/
+QDebug QMessageLogger::info(const QLoggingCategory &cat) const
+{
+ QDebug dbg = QDebug(QtInfoMsg);
+ if (!cat.isInfoEnabled())
+ dbg.stream->message_output = false;
+
+ QMessageLogContext &ctxt = dbg.stream->context;
+ ctxt.copy(context);
+ ctxt.category = cat.categoryName();
+
+ return dbg;
+}
+
+/*!
+ Logs an informational message into category returned by \a catFunc using a QDebug stream.
+
+ \since 5.5
+ \sa qCInfo(), QDebug
+*/
+QDebug QMessageLogger::info(QMessageLogger::CategoryFunction catFunc) const
+{
+ return info((*catFunc)());
+}
+
+#endif
+
#undef qWarning
/*!
Logs a warning message specified with format \a msg. Additional
@@ -840,6 +966,7 @@ static const char timeTokenC[] = "%{time"; //not a typo: this command has argume
static const char backtraceTokenC[] = "%{backtrace"; //ditto
static const char ifCategoryTokenC[] = "%{if-category}";
static const char ifDebugTokenC[] = "%{if-debug}";
+static const char ifInfoTokenC[] = "%{if-info}";
static const char ifWarningTokenC[] = "%{if-warning}";
static const char ifCriticalTokenC[] = "%{if-critical}";
static const char ifFatalTokenC[] = "%{if-fatal}";
@@ -1009,6 +1136,7 @@ void QMessagePattern::setPattern(const QString &pattern)
}
IF_TOKEN(ifCategoryTokenC)
IF_TOKEN(ifDebugTokenC)
+ IF_TOKEN(ifInfoTokenC)
IF_TOKEN(ifWarningTokenC)
IF_TOKEN(ifCriticalTokenC)
IF_TOKEN(ifFatalTokenC)
@@ -1087,6 +1215,9 @@ static void slog2_default_handler(QtMsgType msgType, const char *message)
//Determines the severity level
switch (msgType) {
case QtDebugMsg:
+ severity = SLOG2_DEBUG1;
+ break;
+ case QtInfoMsg:
severity = SLOG2_INFO;
break;
case QtWarningMsg:
@@ -1149,6 +1280,7 @@ QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, con
} else if (token == typeTokenC) {
switch (type) {
case QtDebugMsg: message.append(QLatin1String("debug")); break;
+ case QtInfoMsg: message.append(QLatin1String("info")); break;
case QtWarningMsg: message.append(QLatin1String("warning")); break;
case QtCriticalMsg:message.append(QLatin1String("critical")); break;
case QtFatalMsg: message.append(QLatin1String("fatal")); break;
@@ -1255,6 +1387,7 @@ QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, con
} else if (token == if##LEVEL##TokenC) { \
skip = type != Qt##LEVEL##Msg;
HANDLE_IF_TOKEN(Debug)
+ HANDLE_IF_TOKEN(Info)
HANDLE_IF_TOKEN(Warning)
HANDLE_IF_TOKEN(Critical)
HANDLE_IF_TOKEN(Fatal)
@@ -1290,6 +1423,9 @@ static void systemd_default_message_handler(QtMsgType type,
case QtDebugMsg:
priority = LOG_DEBUG; // Debug-level messages
break;
+ case QtInfoMsg:
+ priority = LOG_INFO; // Informational conditions
+ break;
case QtWarningMsg:
priority = LOG_WARNING; // Warning conditions
break;
@@ -1319,6 +1455,7 @@ static void android_default_message_handler(QtMsgType type,
android_LogPriority priority = ANDROID_LOG_DEBUG;
switch (type) {
case QtDebugMsg: priority = ANDROID_LOG_DEBUG; break;
+ case QtInfoMsg: priority = ANDROID_LOG_INFO; break;
case QtWarningMsg: priority = ANDROID_LOG_WARN; break;
case QtCriticalMsg: priority = ANDROID_LOG_ERROR; break;
case QtFatalMsg: priority = ANDROID_LOG_FATAL; break;
@@ -1609,7 +1746,7 @@ void qErrnoWarning(int code, const char *msg, ...)
tail call optimization.
\endtable
- You can also use conditionals on the type of the message using \c %{if-debug},
+ You can also use conditionals on the type of the message using \c %{if-debug}, \c %{if-info}
\c %{if-warning}, \c %{if-critical} or \c %{if-fatal} followed by an \c %{endif}.
What is inside the \c %{if-*} and \c %{endif} will only be printed if the type matches.
@@ -1618,7 +1755,7 @@ void qErrnoWarning(int code, const char *msg, ...)
Example:
\code
- QT_MESSAGE_PATTERN="[%{time yyyyMMdd h:mm:ss.zzz t} %{if-debug}D%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{file}:%{line} - %{message}"
+ QT_MESSAGE_PATTERN="[%{time yyyyMMdd h:mm:ss.zzz t} %{if-debug}D{%endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{file}:%{line} - %{message}"
\endcode
The default \a pattern is "%{if-category}%{category}: %{endif}%{message}".
diff --git a/src/corelib/global/qlogging.h b/src/corelib/global/qlogging.h
index f9bbf7fcce..829cd7c885 100644
--- a/src/corelib/global/qlogging.h
+++ b/src/corelib/global/qlogging.h
@@ -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.
@@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE
class QDebug;
class QNoDebug;
-enum QtMsgType { QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg, QtSystemMsg = QtCriticalMsg };
+enum QtMsgType { QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg, QtInfoMsg, QtSystemMsg = QtCriticalMsg };
class QMessageLogContext
{
@@ -89,6 +89,7 @@ public:
void debug(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
void noDebug(const char *, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3)
{}
+ void info(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
void warning(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
void critical(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
@@ -96,6 +97,8 @@ public:
void debug(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
void debug(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
+ void info(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
+ void info(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
void warning(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
void warning(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
void critical(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
@@ -110,6 +113,9 @@ public:
QDebug debug() const;
QDebug debug(const QLoggingCategory &cat) const;
QDebug debug(CategoryFunction catFunc) const;
+ QDebug info() const;
+ QDebug info(const QLoggingCategory &cat) const;
+ QDebug info(CategoryFunction catFunc) const;
QDebug warning() const;
QDebug warning(const QLoggingCategory &cat) const;
QDebug warning(CategoryFunction catFunc) const;
@@ -143,6 +149,7 @@ private:
#endif
#define qDebug QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).debug
+#define qInfo QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).info
#define qWarning QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).warning
#define qCritical QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).critical
#define qFatal QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).fatal
@@ -154,6 +161,10 @@ private:
# undef qDebug
# define qDebug QT_NO_QDEBUG_MACRO
#endif
+#if defined(QT_NO_INFO_OUTPUT)
+# undef qInfo
+# define qInfo QT_NO_QDEBUG_MACRO
+#endif
#if defined(QT_NO_WARNING_OUTPUT)
# undef qWarning
# define qWarning QT_NO_QWARNING_MACRO