6.0.0-rc4Source

QMessageLogger Class

The QMessageLogger class generates log messages. More…

Header#include <QMessageLogger>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Types

Public Functions

QMessageLogger()
QMessageLogger(const char *file, int line, const char *function)
QMessageLogger(const char *file, int line, const char *function, const char *category)
voiddebug(const char *msg, ...) const
voiddebug(const QLoggingCategory &cat, const char *msg, ...) const
voiddebug(CategoryFunction catFunc, const char *msg, ...) const
QDebugdebug() const
QDebugdebug(const QLoggingCategory &cat) const
QDebugdebug(CategoryFunction catFunc) const
voidinfo(const char *msg, ...) const
voidinfo(const QLoggingCategory &cat, const char *msg, ...) const
voidinfo(CategoryFunction catFunc, const char *msg, ...) const
QDebuginfo() const
QDebuginfo(const QLoggingCategory &cat) const
QDebuginfo(CategoryFunction catFunc) const
voidwarning(const char *msg, ...) const
voidwarning(const QLoggingCategory &cat, const char *msg, ...) const
voidwarning(CategoryFunction catFunc, const char *msg, ...) const
QDebugwarning() const
QDebugwarning(const QLoggingCategory &cat) const
QDebugwarning(CategoryFunction catFunc) const
voidcritical(const char *msg, ...) const
voidcritical(const QLoggingCategory &cat, const char *msg, ...) const
voidcritical(CategoryFunction catFunc, const char *msg, ...) const
QDebugcritical() const
QDebugcritical(const QLoggingCategory &cat) const
QDebugcritical(CategoryFunction catFunc) const
voidfatal(const char *msg, ...) const
voidfatal(const QLoggingCategory &cat, const char *msg, ...) const
voidfatal(CategoryFunction catFunc, const char *msg, ...) const
QDebugfatal() const
QDebugfatal(const QLoggingCategory &cat) const
QDebugfatal(CategoryFunction catFunc) const
voidnoDebug(const char *, ...) const
QNoDebugnoDebug() const

Detailed Description

QMessageLogger is what the qDebug(), qInfo(), qWarning(), qCritical() and qFatal() macros construct, with the file, line and function of the statement. Use the macros rather than the class:

qInfo() << "listening on port" << port;
qWarning("cannot open %s: %s", path, strerror(errno));

Each function has two forms. One takes a printf() style format string and arguments, and emits the message at once. The other takes no message and returns a QDebug stream, which emits the message when it is destroyed. Both also accept a QLoggingCategory, or a function that returns one, in front of the message; the qCDebug() family of macros does that.

A fatal message aborts the process after the handler has run.

See also QDebug and QLoggingCategory.

Differences from Qt

The QT_NO_DEBUG_OUTPUT, QT_NO_INFO_OUTPUT and QT_NO_WARNING_OUTPUT macros are honoured, but QT_MESSAGELOGCONTEXT is not needed: the context is always present unless QT_NO_MESSAGELOGCONTEXT is defined.

Member Type Documentation

typedef QMessageLogger::CategoryFunction

A function that returns a logging category, such as one declared with Q_DECLARE_LOGGING_CATEGORY().

Member Function Documentation

[constexpr] QMessageLogger::QMessageLogger()

Constructs a logger with no file, line or function, in the category "default".

[constexpr] QMessageLogger::QMessageLogger(const char *file, int line, const char *function)

Constructs a logger for messages from the given file, line and function, in the category "default".

[constexpr] QMessageLogger::QMessageLogger(const char *file, int line, const char *function, const char *category)

Constructs a logger for messages from the given file, line and function, in the category named category.

void QMessageLogger::critical(const char *msg, ...) const

Logs the message msg, formatted like printf(), as a critical message.

void QMessageLogger::critical(const QLoggingCategory &cat, const char *msg, ...) const

This is an overloaded function.

Logs the message msg, formatted like printf(), as a critical message in the category cat if critical messages are enabled for the category.

void QMessageLogger::critical(CategoryFunction catFunc, const char *msg, ...) const

This is an overloaded function.

Logs the message msg, formatted like printf(), as a critical message in the category returned by catFunc if critical messages are enabled for the category.

QDebug QMessageLogger::critical() const

Returns a stream for a critical message. Write the message to it with <<; it is emitted when the stream is destroyed.

QDebug QMessageLogger::critical(const QLoggingCategory &cat) const

This is an overloaded function.

Returns a stream for a critical message in the category cat. Nothing is written if the category does not enable critical messages.

QDebug QMessageLogger::critical(CategoryFunction catFunc) const

This is an overloaded function.

Returns a stream for a critical message in the category returned by catFunc.

void QMessageLogger::debug(const char *msg, ...) const

Logs the message msg, formatted like printf(), as a debug message.

void QMessageLogger::debug(const QLoggingCategory &cat, const char *msg, ...) const

This is an overloaded function.

Logs the message msg, formatted like printf(), as a debug message in the category cat if debug messages are enabled for the category.

void QMessageLogger::debug(CategoryFunction catFunc, const char *msg, ...) const

This is an overloaded function.

Logs the message msg, formatted like printf(), as a debug message in the category returned by catFunc if debug messages are enabled for the category.

QDebug QMessageLogger::debug() const

Returns a stream for a debug message. Write the message to it with <<; it is emitted when the stream is destroyed.

QDebug QMessageLogger::debug(const QLoggingCategory &cat) const

This is an overloaded function.

Returns a stream for a debug message in the category cat. Nothing is written if the category does not enable debug messages.

QDebug QMessageLogger::debug(CategoryFunction catFunc) const

This is an overloaded function.

Returns a stream for a debug message in the category returned by catFunc.

void QMessageLogger::fatal(const char *msg, ...) const

Logs the message msg, formatted like printf(), as a fatal message. Then the process is aborted.

void QMessageLogger::fatal(const QLoggingCategory &cat, const char *msg, ...) const

This is an overloaded function.

Logs the message msg, formatted like printf(), as a fatal message in the category cat. Then the process is aborted.

void QMessageLogger::fatal(CategoryFunction catFunc, const char *msg, ...) const

This is an overloaded function.

Logs the message msg, formatted like printf(), as a fatal message in the category returned by catFunc. Then the process is aborted.

QDebug QMessageLogger::fatal() const

Returns a stream for a fatal message. Write the message to it with <<; it is emitted when the stream is destroyed. Then the process is aborted.

QDebug QMessageLogger::fatal(const QLoggingCategory &cat) const

This is an overloaded function.

Returns a stream for a fatal message in the category cat. Nothing is written if the category does not enable fatal messages.

QDebug QMessageLogger::fatal(CategoryFunction catFunc) const

This is an overloaded function.

Returns a stream for a fatal message in the category returned by catFunc.

void QMessageLogger::info(const char *msg, ...) const

Logs the message msg, formatted like printf(), as an info message.

void QMessageLogger::info(const QLoggingCategory &cat, const char *msg, ...) const

This is an overloaded function.

Logs the message msg, formatted like printf(), as an info message in the category cat if info messages are enabled for the category.

void QMessageLogger::info(CategoryFunction catFunc, const char *msg, ...) const

This is an overloaded function.

Logs the message msg, formatted like printf(), as an info message in the category returned by catFunc if info messages are enabled for the category.

QDebug QMessageLogger::info() const

Returns a stream for an info message. Write the message to it with <<; it is emitted when the stream is destroyed.

QDebug QMessageLogger::info(const QLoggingCategory &cat) const

This is an overloaded function.

Returns a stream for an info message in the category cat. Nothing is written if the category does not enable info messages.

QDebug QMessageLogger::info(CategoryFunction catFunc) const

This is an overloaded function.

Returns a stream for an info message in the category returned by catFunc.

void QMessageLogger::noDebug(const char *, ...) const

Does nothing. This is what qDebug(), qInfo() and qWarning() call when QT_NO_DEBUG_OUTPUT, QT_NO_INFO_OUTPUT or QT_NO_WARNING_OUTPUT is defined, so that the message is compiled out.

QNoDebug QMessageLogger::noDebug() const

This is an overloaded function.

Returns a stream that discards everything written to it.

void QMessageLogger::warning(const char *msg, ...) const

Logs the message msg, formatted like printf(), as a warning message.

void QMessageLogger::warning(const QLoggingCategory &cat, const char *msg, ...) const

This is an overloaded function.

Logs the message msg, formatted like printf(), as a warning message in the category cat if warning messages are enabled for the category.

void QMessageLogger::warning(CategoryFunction catFunc, const char *msg, ...) const

This is an overloaded function.

Logs the message msg, formatted like printf(), as a warning message in the category returned by catFunc if warning messages are enabled for the category.

QDebug QMessageLogger::warning() const

Returns a stream for a warning message. Write the message to it with <<; it is emitted when the stream is destroyed.

QDebug QMessageLogger::warning(const QLoggingCategory &cat) const

This is an overloaded function.

Returns a stream for a warning message in the category cat. Nothing is written if the category does not enable warning messages.

QDebug QMessageLogger::warning(CategoryFunction catFunc) const

This is an overloaded function.

Returns a stream for a warning message in the category returned by catFunc.