File indexing completed on 2025-09-18 09:26:35
0001
0002
0003
0004 #ifndef QLOGGING_H
0005 #define QLOGGING_H
0006
0007 #include <QtCore/qtclasshelpermacros.h>
0008 #include <QtCore/qtconfigmacros.h>
0009 #include <QtCore/qtcoreexports.h>
0010 #include <QtCore/qcontainerfwd.h>
0011
0012 #if 0
0013
0014 #pragma qt_no_master_include
0015 #pragma qt_class(QtLogging)
0016 #endif
0017
0018 QT_BEGIN_NAMESPACE
0019
0020
0021
0022
0023
0024
0025 class QDebug;
0026 class QNoDebug;
0027
0028
0029 enum QtMsgType {
0030 QtDebugMsg,
0031 QT7_ONLY(QtInfoMsg,)
0032 QtWarningMsg,
0033 QtCriticalMsg,
0034 QtFatalMsg,
0035 QT6_ONLY(QtInfoMsg,)
0036 #if QT_DEPRECATED_SINCE(6, 7)
0037 QtSystemMsg Q_DECL_ENUMERATOR_DEPRECATED_X("Use QtCriticalMsg instead.") = QtCriticalMsg
0038 #endif
0039 };
0040
0041 class QInternalMessageLogContext;
0042 class QMessageLogContext
0043 {
0044 Q_DISABLE_COPY(QMessageLogContext)
0045 public:
0046 static constexpr int CurrentVersion = 2;
0047 constexpr QMessageLogContext() noexcept = default;
0048 constexpr QMessageLogContext(const char *fileName, int lineNumber, const char *functionName, const char *categoryName) noexcept
0049 : line(lineNumber), file(fileName), function(functionName), category(categoryName) {}
0050
0051 int version = CurrentVersion;
0052 int line = 0;
0053 const char *file = nullptr;
0054 const char *function = nullptr;
0055 const char *category = nullptr;
0056
0057 private:
0058 QMessageLogContext ©ContextFrom(const QMessageLogContext &logContext) noexcept;
0059
0060 friend class QInternalMessageLogContext;
0061 friend class QMessageLogger;
0062 };
0063
0064 class QLoggingCategory;
0065
0066 #if defined(Q_CC_MSVC_ONLY)
0067 # define QT_MESSAGE_LOGGER_NORETURN
0068 #else
0069 # define QT_MESSAGE_LOGGER_NORETURN Q_NORETURN
0070 #endif
0071
0072 class Q_CORE_EXPORT QMessageLogger
0073 {
0074 Q_DISABLE_COPY(QMessageLogger)
0075 public:
0076 constexpr QMessageLogger() : context() {}
0077 constexpr QMessageLogger(const char *file, int line, const char *function)
0078 : context(file, line, function, "default") {}
0079 constexpr QMessageLogger(const char *file, int line, const char *function, const char *category)
0080 : context(file, line, function, category) {}
0081
0082 void debug(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
0083 void noDebug(const char *, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3)
0084 {}
0085 void info(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
0086 Q_DECL_COLD_FUNCTION
0087 void warning(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
0088 Q_DECL_COLD_FUNCTION
0089 void critical(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
0090 QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION
0091 void fatal(const char *msg, ...) const noexcept Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
0092
0093 typedef const QLoggingCategory &(*CategoryFunction)();
0094
0095 void debug(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0096 void debug(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0097 void info(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0098 void info(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0099 Q_DECL_COLD_FUNCTION
0100 void warning(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0101 Q_DECL_COLD_FUNCTION
0102 void warning(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0103 Q_DECL_COLD_FUNCTION
0104 void critical(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0105 Q_DECL_COLD_FUNCTION
0106 void critical(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0107 QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION
0108 void fatal(const QLoggingCategory &cat, const char *msg, ...) const noexcept Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0109 QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION
0110 void fatal(CategoryFunction catFunc, const char *msg, ...) const noexcept Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0111
0112 #ifndef QT_NO_DEBUG_STREAM
0113 QDebug debug() const;
0114 QDebug debug(const QLoggingCategory &cat) const;
0115 QDebug debug(CategoryFunction catFunc) const;
0116 QDebug info() const;
0117 QDebug info(const QLoggingCategory &cat) const;
0118 QDebug info(CategoryFunction catFunc) const;
0119 Q_DECL_COLD_FUNCTION
0120 QDebug warning() const;
0121 Q_DECL_COLD_FUNCTION
0122 QDebug warning(const QLoggingCategory &cat) const;
0123 Q_DECL_COLD_FUNCTION
0124 QDebug warning(CategoryFunction catFunc) const;
0125 Q_DECL_COLD_FUNCTION
0126 QDebug critical() const;
0127 Q_DECL_COLD_FUNCTION
0128 QDebug critical(const QLoggingCategory &cat) const;
0129 Q_DECL_COLD_FUNCTION
0130 QDebug critical(CategoryFunction catFunc) const;
0131 Q_DECL_COLD_FUNCTION
0132 QDebug fatal() const;
0133 Q_DECL_COLD_FUNCTION
0134 QDebug fatal(const QLoggingCategory &cat) const;
0135 Q_DECL_COLD_FUNCTION
0136 QDebug fatal(CategoryFunction catFunc) const;
0137
0138 QNoDebug noDebug() const noexcept;
0139 #endif
0140
0141 private:
0142 QMessageLogContext context;
0143 };
0144
0145 #undef QT_MESSAGE_LOGGER_NORETURN
0146
0147 #if !defined(QT_MESSAGELOGCONTEXT) && !defined(QT_NO_MESSAGELOGCONTEXT)
0148 # if defined(QT_NO_DEBUG)
0149 # define QT_NO_MESSAGELOGCONTEXT
0150 # else
0151 # define QT_MESSAGELOGCONTEXT
0152 # endif
0153 #endif
0154
0155 #ifdef QT_MESSAGELOGCONTEXT
0156 #define QT_MESSAGELOG_FILE static_cast<const char *>(__FILE__)
0157 #define QT_MESSAGELOG_LINE __LINE__
0158 #define QT_MESSAGELOG_FUNC static_cast<const char *>(Q_FUNC_INFO)
0159 #else
0160 #define QT_MESSAGELOG_FILE nullptr
0161 #define QT_MESSAGELOG_LINE 0
0162 #define QT_MESSAGELOG_FUNC nullptr
0163 #endif
0164
0165 #define qDebug QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).debug
0166 #define qInfo QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).info
0167 #define qWarning QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).warning
0168 #define qCritical QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).critical
0169 #define qFatal QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).fatal
0170
0171 #define QT_NO_QDEBUG_MACRO while (false) QMessageLogger().noDebug
0172
0173 #if defined(QT_NO_DEBUG_OUTPUT)
0174 # undef qDebug
0175 # define qDebug QT_NO_QDEBUG_MACRO
0176 #endif
0177 #if defined(QT_NO_INFO_OUTPUT)
0178 # undef qInfo
0179 # define qInfo QT_NO_QDEBUG_MACRO
0180 #endif
0181 #if defined(QT_NO_WARNING_OUTPUT)
0182 # undef qWarning
0183 # define qWarning QT_NO_QDEBUG_MACRO
0184 #endif
0185
0186 Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context,
0187 const QString &message);
0188
0189 Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(int code, const char *msg, ...);
0190 Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(const char *msg, ...);
0191
0192 typedef void (*QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &);
0193 Q_CORE_EXPORT QtMessageHandler qInstallMessageHandler(QtMessageHandler);
0194
0195 Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern);
0196 Q_CORE_EXPORT QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context,
0197 const QString &buf);
0198
0199 Q_DECL_COLD_FUNCTION
0200 Q_CORE_EXPORT QString qt_error_string(int errorCode = -1);
0201
0202 QT_END_NAMESPACE
0203 #endif