QMessageLogger Class
The QMessageLogger class generates log messages. More…
| Header | #include <QMessageLogger> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
List of all members, including inherited members
Public Types
| typedef | CategoryFunction |
Public Functions
| QMessageLogger() | |
| QMessageLogger(const char *file, int line, const char *function) | |
| QMessageLogger(const char *file, int line, const char *function, const char *category) | |
| void | debug(const char *msg, ...) const |
| void | debug(const QLoggingCategory &cat, const char *msg, ...) const |
| void | debug(CategoryFunction catFunc, const char *msg, ...) const |
| QDebug | debug() const |
| QDebug | debug(const QLoggingCategory &cat) const |
| QDebug | debug(CategoryFunction catFunc) const |
| void | info(const char *msg, ...) const |
| void | info(const QLoggingCategory &cat, const char *msg, ...) const |
| void | info(CategoryFunction catFunc, const char *msg, ...) const |
| QDebug | info() const |
| QDebug | info(const QLoggingCategory &cat) const |
| QDebug | info(CategoryFunction catFunc) const |
| void | warning(const char *msg, ...) const |
| void | warning(const QLoggingCategory &cat, const char *msg, ...) const |
| void | warning(CategoryFunction catFunc, const char *msg, ...) const |
| QDebug | warning() const |
| QDebug | warning(const QLoggingCategory &cat) const |
| QDebug | warning(CategoryFunction catFunc) const |
| void | critical(const char *msg, ...) const |
| void | critical(const QLoggingCategory &cat, const char *msg, ...) const |
| void | critical(CategoryFunction catFunc, const char *msg, ...) const |
| QDebug | critical() const |
| QDebug | critical(const QLoggingCategory &cat) const |
| QDebug | critical(CategoryFunction catFunc) const |
| void | fatal(const char *msg, ...) const |
| void | fatal(const QLoggingCategory &cat, const char *msg, ...) const |
| void | fatal(CategoryFunction catFunc, const char *msg, ...) const |
| QDebug | fatal() const |
| QDebug | fatal(const QLoggingCategory &cat) const |
| QDebug | fatal(CategoryFunction catFunc) const |
| void | noDebug(const char *, ...) const |
| QNoDebug | noDebug() 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
QMessageLogger::QMessageLogger()
Constructs a logger with no file, line or function, in the category "default".
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".
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.