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>
This commit is contained in:
Kai Koehne 2014-12-04 16:57:32 +01:00
parent 4c980aedc1
commit ef6279fd51
23 changed files with 462 additions and 63 deletions

View File

@ -1,6 +1,6 @@
/****************************************************************************
**
** Copyright (C) 2013 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 documentation of the Qt Toolkit.
@ -253,6 +253,9 @@ void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QS
case QtDebugMsg:
fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtInfoMsg:
fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtWarningMsg:
fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
@ -285,6 +288,14 @@ qDebug() << "Brush:" << myQBrush << "Other value:" << i;
//! [25]
//! [qInfo_printf]
qInfo("Items in list: %d", myList.size());
//! [qInfo_printf]
//! [qInfo_stream]
qInfo() << "Brush:" << myQBrush << "Other value:" << i;
//! [qInfo_stream]
//! [26]
void f(int c)
{

View File

@ -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 examples of the Qt Toolkit.
@ -117,6 +117,11 @@ oldCategoryFilter = QLoggingCategory::installFilter(myCategoryFilter);
//![10]
}
//![qcinfo_stream]
QLoggingCategory category("driver.usb");
qCInfo(category) << "an informational message";
//![qcinfo_stream]
{
//![11]
QLoggingCategory category("driver.usb");
@ -138,6 +143,13 @@ oldCategoryFilter = QLoggingCategory::installFilter(myCategoryFilter);
//![13]
}
{
//![qcinfo_printf]
QLoggingCategory category("driver.usb");
qCInfo(category, "an informational message logged into category %s", category.categoryName());
//![qcinfo_printf]
}
{
//![14]
QLoggingCategory category("driver.usb");

View File

@ -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}
*/

View File

@ -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}".

View File

@ -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

View File

@ -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.
@ -438,6 +456,47 @@ void QLoggingCategory::setFilterRules(const QString &rules)
\sa qDebug()
*/
/*!
\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

View File

@ -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.
@ -53,10 +53,12 @@ public:
#ifdef Q_ATOMIC_INT8_IS_SUPPORTED
bool isDebugEnabled() const { return bools.enabledDebug.load(); }
bool isInfoEnabled() const { return bools.enabledInfo.load(); }
bool isWarningEnabled() const { return bools.enabledWarning.load(); }
bool isCriticalEnabled() const { return bools.enabledCritical.load(); }
#else
bool isDebugEnabled() const { return enabled.load() >> DebugShift & 1; }
bool isInfoEnabled() const { return enabled.load() >> InfoShift & 1; }
bool isWarningEnabled() const { return enabled.load() >> WarningShift & 1; }
bool isCriticalEnabled() const { return enabled.load() >> CriticalShift & 1; }
#endif
@ -80,9 +82,9 @@ private:
const char *name;
#ifdef Q_BIG_ENDIAN
enum { DebugShift = 0, WarningShift = 8, CriticalShift = 16 };
enum { DebugShift = 0, WarningShift = 8, CriticalShift = 16, InfoShift = 24 };
#else
enum { DebugShift = 24, WarningShift = 16, CriticalShift = 8 };
enum { DebugShift = 24, WarningShift = 16, CriticalShift = 8, InfoShift = 0};
#endif
struct AtomicBools {
@ -90,6 +92,7 @@ private:
QBasicAtomicInteger<bool> enabledDebug;
QBasicAtomicInteger<bool> enabledWarning;
QBasicAtomicInteger<bool> enabledCritical;
QBasicAtomicInteger<bool> enabledInfo;
#endif
};
union {
@ -114,6 +117,9 @@ private:
#define qCDebug(category, ...) \
for (bool qt_category_enabled = category().isDebugEnabled(); qt_category_enabled; qt_category_enabled = false) \
QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, category().categoryName()).debug(__VA_ARGS__)
#define qCInfo(category, ...) \
for (bool qt_category_enabled = category().isInfoEnabled(); qt_category_enabled; qt_category_enabled = false) \
QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, category().categoryName()).info(__VA_ARGS__)
#define qCWarning(category, ...) \
for (bool qt_category_enabled = category().isWarningEnabled(); qt_category_enabled; qt_category_enabled = false) \
QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC, category().categoryName()).warning(__VA_ARGS__)
@ -133,6 +139,7 @@ private:
// check for enabled category inside QMessageLogger.
#define qCDebug qDebug
#define qCInfo qInfo
#define qCWarning qWarning
#define qCCritical qCritical
@ -142,6 +149,10 @@ private:
# undef qCDebug
# define qCDebug(category) QT_NO_QDEBUG_MACRO()
#endif
#if defined(QT_NO_INFO_OUTPUT)
# undef qCInfo
# define qCInfo(category) QT_NO_QDEBUG_MACRO()
#endif
#if defined(QT_NO_WARNING_OUTPUT)
# undef qCWarning
# define qCWarning(category) QT_NO_QWARNING_MACRO()

View File

@ -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.
@ -124,6 +124,10 @@ void QLoggingRule::parse(const QStringRef &pattern)
p = QStringRef(pattern.string(), pattern.position(),
pattern.length() - 6); // strlen(".debug")
messageType = QtDebugMsg;
} else if (pattern.endsWith(QLatin1String(".info"))) {
p = QStringRef(pattern.string(), pattern.position(),
pattern.length() - 5); // strlen(".info")
messageType = QtInfoMsg;
} else if (pattern.endsWith(QLatin1String(".warning"))) {
p = QStringRef(pattern.string(), pattern.position(),
pattern.length() - 8); // strlen(".warning")
@ -392,6 +396,7 @@ void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat)
QtMsgType enableForLevel = reg->categories.value(cat);
bool debug = (enableForLevel == QtDebugMsg);
bool info = (enableForLevel <= QtInfoMsg);
bool warning = (enableForLevel <= QtWarningMsg);
bool critical = (enableForLevel <= QtCriticalMsg);
@ -409,6 +414,9 @@ void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat)
int filterpass = item.pass(categoryName, QtDebugMsg);
if (filterpass != 0)
debug = (filterpass > 0);
filterpass = item.pass(categoryName, QtInfoMsg);
if (filterpass != 0)
info = (filterpass > 0);
filterpass = item.pass(categoryName, QtWarningMsg);
if (filterpass != 0)
warning = (filterpass > 0);
@ -418,6 +426,7 @@ void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat)
}
cat->setEnabled(QtDebugMsg, debug);
cat->setEnabled(QtInfoMsg, info);
cat->setEnabled(QtWarningMsg, warning);
cat->setEnabled(QtCriticalMsg, critical);
}

View File

@ -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 QtTest module of the Qt Toolkit.
@ -72,7 +72,8 @@ public:
QSystem,
QFatal,
Skip,
Info
Info,
QInfo
};
QAbstractTestLogger(const char *filename);

View File

@ -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 QtTest module of the Qt Toolkit.
@ -105,6 +105,8 @@ namespace QTest {
return "QWARN ";
case QAbstractTestLogger::QDebug:
return "QDEBUG ";
case QAbstractTestLogger::QInfo:
return "QINFO ";
case QAbstractTestLogger::QSystem:
return "QSYSTEM";
case QAbstractTestLogger::QFatal:

View File

@ -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 QtTest module of the Qt Toolkit.
@ -2597,7 +2597,7 @@ void QTest::qWarn(const char *message, const char *file, int line)
}
/*!
Ignores messages created by qDebug() or qWarning(). If the \a message
Ignores messages created by qDebug(), qInfo() or qWarning(). If the \a message
with the corresponding \a type is outputted, it will be removed from the
test log. If the test finished and the \a message was not outputted,
a test failure is appended to the test log.
@ -2621,7 +2621,7 @@ void QTest::ignoreMessage(QtMsgType type, const char *message)
/*!
\overload
Ignores messages created by qDebug() or qWarning(). If the message
Ignores messages created by qDebug(), qInfo() or qWarning(). If the message
matching \a messagePattern
with the corresponding \a type is outputted, it will be removed from the
test log. If the test finished and the message was not outputted,

View File

@ -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 QtTest module of the Qt Toolkit.
@ -295,6 +295,9 @@ namespace QTest {
case QtDebugMsg:
QTest::TestLoggers::addMessage(QAbstractTestLogger::QDebug, msg);
break;
case QtInfoMsg:
QTest::TestLoggers::addMessage(QAbstractTestLogger::QInfo, msg);
break;
case QtCriticalMsg:
QTest::TestLoggers::addMessage(QAbstractTestLogger::QSystem, msg);
break;

View File

@ -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 QtTest module of the Qt Toolkit.
@ -55,6 +55,8 @@ namespace QTest {
return "system";
case QAbstractTestLogger::QDebug:
return "qdebug";
case QAbstractTestLogger::QInfo:
return "qinfo";
case QAbstractTestLogger::QWarning:
return "qwarn";
case QAbstractTestLogger::QFatal:

View File

@ -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 QtTest module of the Qt Toolkit.
@ -298,6 +298,9 @@ void QXunitTestLogger::addMessage(MessageTypes type, const QString &message, con
case QAbstractTestLogger::QDebug:
typeBuf = "qdebug";
break;
case QAbstractTestLogger::QInfo:
typeBuf = "qinfo";
break;
case QAbstractTestLogger::QWarning:
typeBuf = "qwarn";
break;

View File

@ -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 test suite of the Qt Toolkit.
@ -73,6 +73,7 @@ int main(int argc, char **argv)
qSetMessagePattern("[%{type}] %{message}");
qDebug("qDebug");
qInfo("qInfo");
qWarning("qWarning");
qCritical("qCritical");

View File

@ -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>
** Contact: http://www.qt-project.org/legal
**
@ -730,10 +730,11 @@ void tst_qmessagehandler::qMessagePattern_data()
<< "static destructor"
<< "debug tst_qlogging 65 MyClass::myFunction from_a_function 34"
<< "debug tst_qlogging 75 main qDebug"
<< "warning tst_qlogging 76 main qWarning"
<< "critical tst_qlogging 77 main qCritical"
<< "warning tst_qlogging 80 main qDebug with category"
<< "debug tst_qlogging 84 main qDebug2");
<< "info tst_qlogging 76 main qInfo"
<< "warning tst_qlogging 77 main qWarning"
<< "critical tst_qlogging 78 main qCritical"
<< "warning tst_qlogging 81 main qDebug with category"
<< "debug tst_qlogging 85 main qDebug2");
QTest::newRow("invalid") << "PREFIX: %{unknown} %{message}" << false << (QList<QByteArray>()
@ -877,6 +878,7 @@ void tst_qmessagehandler::setMessagePattern()
//qDebug() << output;
QByteArray expected = "static constructor\n"
"[debug] qDebug\n"
"[info] qInfo\n"
"[warning] qWarning\n"
"[critical] qCritical\n"
"[warning] qDebug with category\n";
@ -908,10 +910,13 @@ void tst_qmessagehandler::formatLogMessage_data()
<< QtDebugMsg << BA("main.cpp") << 1 << BA("func") << BA("") << "msg";
// test the if conditions
QString format = "[%{if-debug}D%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{if-category}%{category}: %{endif}%{message}";
QString format = "[%{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{if-category}%{category}: %{endif}%{message}";
QTest::newRow("if-debug")
<< format << "[D] msg"
<< QtDebugMsg << BA("") << 0 << BA("func") << QByteArray() << "msg";
QTest::newRow("if_info")
<< format << "[I] msg"
<< QtInfoMsg << BA("") << 0 << BA("func") << QByteArray() << "msg";
QTest::newRow("if_warning")
<< format << "[W] msg"
<< QtWarningMsg << BA("") << 0 << BA("func") << QByteArray() << "msg";

View File

@ -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 test suite of the Qt Toolkit.
@ -57,6 +57,7 @@ QByteArray qMyMessageFormatString(QtMsgType type, const QMessageLogContext &cont
message.append(context.category);
switch (type) {
case QtDebugMsg: message.append(".debug"); break;
case QtInfoMsg: message.append(".info"); break;
case QtWarningMsg: message.append(".warning"); break;
case QtCriticalMsg:message.append(".critical"); break;
case QtFatalMsg: message.append(".fatal"); break;
@ -339,6 +340,11 @@ private slots:
qDebug("%s", "Check debug with no filter active");
QCOMPARE(logMessage, buf);
// Check default info
buf = QStringLiteral("default.info: Check info with no filter active");
qInfo("%s", "Check info with no filter active");
QCOMPARE(logMessage, buf);
// Check default warning
buf = QStringLiteral("default.warning: Check warning with no filter active");
qWarning("%s", "Check warning with no filter active");
@ -407,6 +413,13 @@ private slots:
qCDebug(defaultCategory, "Check debug with no filter active");
QCOMPARE(logMessage, buf);
// Check default info
buf = QStringLiteral("default.info: Check info with no filter active");
qCInfo(defaultCategory) << "Check info with no filter active";
QCOMPARE(logMessage, buf);
qCInfo(defaultCategory, "Check info with no filter active");
QCOMPARE(logMessage, buf);
// Check default warning
buf = QStringLiteral("default.warning: Check warning with no filter active");
qCWarning(defaultCategory) << "Check warning with no filter active";
@ -432,6 +445,11 @@ private slots:
qCDebug(customCategory) << "Check debug with no filter active";
QCOMPARE(logMessage, buf);
// Check custom info
buf = QStringLiteral("custom.info: Check info with no filter active");
qCInfo(customCategory) << "Check info with no filter active";
QCOMPARE(logMessage, buf);
// Check custom warning
buf = QStringLiteral("custom.warning: Check warning with no filter active");
qCWarning(customCategory) << "Check warning with no filter active";
@ -493,7 +511,7 @@ private slots:
usedefaultformat = false;
}
// Check the Debug, Warning and critical without having category active. should be active.
// Check the Debug, Info, Warning and critical without having category active. should be active.
void checkNoCategoryLogActive()
{
// Check default debug
@ -501,6 +519,11 @@ private slots:
qDebug() << "Check default Debug with no log active";
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
// Check default info
buf = QStringLiteral("default.info: Check default Info with no log active");
qInfo() << "Check default Info with no log active";
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
// Check default warning
buf = QStringLiteral("default.warning: Check default Warning with no log active");
qWarning() << "Check default Warning with no log active";
@ -514,8 +537,11 @@ private slots:
// Check category debug
buf = QStringLiteral("tst.log.debug: Check category Debug with no log active");
qCDebug(TST_LOG) << "Check category Debug with no log active";
QCOMPARE(logMessage, buf);
// Check category info
buf = QStringLiteral("tst.log.info: Check category Info with no log active");
qCInfo(TST_LOG) << "Check category Info with no log active";
QCOMPARE(logMessage, buf);
// Check default warning
buf = QStringLiteral("tst.log.warning: Check category Warning with no log active");
@ -550,6 +576,9 @@ private slots:
qCDebug(TST_LOG) << "DebugType";
buf = QStringLiteral("tst.log.debug: DebugType");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qCInfo(TST_LOG) << "InfoType";
buf = QStringLiteral("tst.log.info: InfoType");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qCWarning(TST_LOG) << "WarningType";
buf = QStringLiteral("tst.log.warning: WarningType");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
@ -561,11 +590,13 @@ private slots:
void checkLegacyLogs()
{
logMessage = "";
// all are on by default
qDebug() << "DefaultDebug";
QString buf = QStringLiteral("default.debug: DefaultDebug");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
// debug off by default, warning and critical are on
qInfo() << "DefaultInfo";
buf = QStringLiteral("default.info: DefaultInfo");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qWarning() << "DefaultWarning";
buf = QStringLiteral("default.warning: DefaultWarning");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
@ -573,12 +604,16 @@ private slots:
buf = QStringLiteral("default.critical: DefaultCritical");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
// Enable debug
_config->addKey("default.debug", true);
// Disable debug
_config->addKey("default.debug", false);
QLoggingCategory::setFilterRules(_config->array());
logMessage = "no change";
qDebug() << "DefaultDebug1";
buf = QStringLiteral("default.debug: DefaultDebug1");
buf = QStringLiteral("no change");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qInfo() << "DefaultInfo1";
buf = QStringLiteral("default.info: DefaultInfo1");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qWarning() << "DefaultWarning1";
buf = QStringLiteral("default.warning: DefaultWarning1");
@ -587,7 +622,11 @@ private slots:
buf = QStringLiteral("default.critical: DefaultCritical1");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
// Disable warning
_config->clear();
QLoggingCategory::setFilterRules(_config->array());
// Disable info, warning
_config->addKey("default.info", false);
_config->addKey("default.warning", false);
QLoggingCategory::setFilterRules(_config->array());
@ -595,6 +634,9 @@ private slots:
buf = QStringLiteral("default.debug: DefaultDebug2");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
logMessage = "no change";
qInfo() << "DefaultInfo2";
buf = QStringLiteral("no change");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qWarning() << "DefaultWarning2";
buf = QStringLiteral("no change");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
@ -611,6 +653,8 @@ private slots:
qDebug() << "DefaultDebug3";
buf = QStringLiteral("no change");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qInfo() << "DefaultInfo3";
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qWarning() << "DefaultWarning3";
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qCritical() << "DefaultCritical3";
@ -619,6 +663,7 @@ private slots:
// Enable default logs
_config->addKey("default.critical", true);
_config->addKey("default.warning", true);
_config->addKey("default.info", true);
_config->addKey("default.debug", true);
QLoggingCategory::setFilterRules(_config->array());
@ -626,6 +671,9 @@ private slots:
qDebug() << "DefaultDebug4";
buf = QStringLiteral("default.debug: DefaultDebug4");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qInfo() << "DefaultInfo4";
buf = QStringLiteral("default.info: DefaultInfo4");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qWarning() << "DefaultWarning4";
buf = QStringLiteral("default.warning: DefaultWarning4");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
@ -642,6 +690,8 @@ private slots:
buf = QStringLiteral("no change");
qDebug() << "DefaultDebug5";
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qDebug() << "DefaultInfo5";
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qWarning() << "DefaultWarning5";
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qCritical() << "DefaultCritical5";
@ -711,6 +761,7 @@ private slots:
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
logMessage = "no change";
buf = QStringLiteral("no change");
qCInfo(Digia_Oulu_Office_com) << "Info: Digia.Oulu.Office.com 4";
qCWarning(Digia_Oulu_Office_com) << "Warning: Digia.Oulu.Office.com 4";
qCCritical(Digia_Berlin_Office_com) << "Critical: Digia.Berlin.Office.com 4";
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
@ -723,6 +774,9 @@ private slots:
qCDebug(Digia_Oslo_Office_com) << "Debug: Digia.Oslo.Office.com 5";
buf = QStringLiteral("Digia.Oslo.Office.com.debug: Debug: Digia.Oslo.Office.com 5");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qCInfo(Digia_Oulu_Office_com) << "Info: Digia.Oulu.Office.com 5";
buf = QStringLiteral("Digia.Oulu.Office.com.info: Info: Digia.Oulu.Office.com 5");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qCWarning(Digia_Oulu_Office_com) << "Warning: Digia.Oulu.Office.com 5";
buf = QStringLiteral("Digia.Oulu.Office.com.warning: Warning: Digia.Oulu.Office.com 5");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
@ -737,6 +791,7 @@ private slots:
logMessage = "no change";
buf = QStringLiteral("no change");
qCDebug(Digia_Oslo_Office_com) << "Debug: Digia.Oslo.Office.com 6";
qCInfo(Digia_Oslo_Office_com) << "Info: Digia.Oslo.Office.com 6";
qCWarning(Digia_Oulu_Office_com) << "Warning: Digia.Oulu.Office.com 6";
qCCritical(Digia_Berlin_Office_com) << "Critical: Digia.Berlin.Office.com 6";
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
@ -747,6 +802,9 @@ private slots:
qCDebug(Digia_Oslo_Office_com) << "Debug: Digia.Oslo.Office.com 7";
buf = QStringLiteral("Digia.Oslo.Office.com.debug: Debug: Digia.Oslo.Office.com 7");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qCInfo(Digia_Oulu_Office_com) << "Info: Digia.Oulu.Office.com 7";
buf = QStringLiteral("Digia.Oulu.Office.com.info: Info: Digia.Oulu.Office.com 7");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
qCWarning(Digia_Oulu_Office_com) << "Warning: Digia.Oulu.Office.com 7";
buf = QStringLiteral("Digia.Oulu.Office.com.warning: Warning: Digia.Oulu.Office.com 7");
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
@ -770,6 +828,10 @@ private slots:
qCDebug(mycategoryobject) << "My Category Object";
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
buf = QStringLiteral("LoggingCategoryObject.info: My Category Object");
qCInfo(mycategoryobject) << "My Category Object";
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
buf = QStringLiteral("LoggingCategoryObject.warning: My Category Object");
qCWarning(mycategoryobject) << "My Category Object";
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
@ -787,6 +849,10 @@ private slots:
qCWarning(mycategoryobject) << "My Category Object";
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
buf = QStringLiteral("LoggingCategoryObject.info: My Category Object");
qCInfo(mycategoryobject) << "My Category Object";
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));
buf = QStringLiteral("LoggingCategoryObject.critical: My Category Object");
qCCritical(mycategoryobject) << "My Category Object";
QCOMPARE(cleanLogLine(logMessage), cleanLogLine(buf));

View File

@ -20,6 +20,12 @@
<Message type="qdebug" file="" line="0">
<Description><![CDATA[Debug]]></Description>
</Message>
<Message type="qinfo" file="" line="0">
<Description><![CDATA[Info]]></Description>
</Message>
<Message type="qinfo" file="" line="0">
<Description><![CDATA[Info]]></Description>
</Message>
<Message type="qdebug" file="" line="0">
<Description><![CDATA[Baba]]></Description>
</Message>

View File

@ -5,6 +5,8 @@ QWARN : tst_Warnings::testWarnings() Warning
QWARN : tst_Warnings::testWarnings() Warning
QDEBUG : tst_Warnings::testWarnings() Debug
QDEBUG : tst_Warnings::testWarnings() Debug
QINFO : tst_Warnings::testWarnings() Info
QINFO : tst_Warnings::testWarnings() Info
QDEBUG : tst_Warnings::testWarnings() Baba
QDEBUG : tst_Warnings::testWarnings() Baba
QDEBUG : tst_Warnings::testWarnings() Bubublabla

View File

@ -22,6 +22,12 @@
<Message type="qdebug" file="" line="0">
<Description><![CDATA[Debug]]></Description>
</Message>
<Message type="qinfo" file="" line="0">
<Description><![CDATA[Info]]></Description>
</Message>
<Message type="qinfo" file="" line="0">
<Description><![CDATA[Info]]></Description>
</Message>
<Message type="qdebug" file="" line="0">
<Description><![CDATA[Baba]]></Description>
</Message>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite errors="15" failures="4" tests="6" name="tst_Warnings">
<testsuite errors="17" failures="4" tests="6" name="tst_Warnings">
<properties>
<property value="@INSERT_QT_VERSION_HERE@" name="QTestVersion"/>
<property value="@INSERT_QT_VERSION_HERE@" name="QtVersion"/>
@ -11,6 +11,8 @@
<!-- message="Warning" type="qwarn" -->
<!-- message="Debug" type="qdebug" -->
<!-- message="Debug" type="qdebug" -->
<!-- message="Info" type="qinfo" -->
<!-- message="Info" type="qinfo" -->
<!-- message="Baba" type="qdebug" -->
<!-- message="Baba" type="qdebug" -->
<!-- message="Bubublabla" type="qdebug" -->
@ -39,6 +41,8 @@
<![CDATA[Warning]]>
<![CDATA[Debug]]>
<![CDATA[Debug]]>
<![CDATA[Info]]>
<![CDATA[Info]]>
<![CDATA[Baba]]>
<![CDATA[Baba]]>
<![CDATA[Bubublabla]]>

View File

@ -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 test suite of the Qt Toolkit.
@ -83,6 +83,7 @@ void tst_Silent::messages()
QWARN("This is an internal testlib warning that should not appear in silent test output");
qDebug("This is a debug message that should not appear in silent test output");
qCritical("This is a critical message that should not appear in silent test output");
qInfo("This is an info message that should not appear in silent test output");
QTestLog::info("This is an internal testlib info message that should not appear in silent test output", __FILE__, __LINE__);
qFatal("This is a fatal error message that should still appear in silent test output");
}

View File

@ -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 test suite of the Qt Toolkit.
@ -63,6 +63,13 @@ void tst_Warnings::testWarnings()
qDebug("Debug");
qInfo("Info");
QTest::ignoreMessage(QtInfoMsg, "Info");
qInfo("Info");
qInfo("Info");
QTest::ignoreMessage(QtDebugMsg, "Bubu");
qDebug("Baba");
qDebug("Bubu");