Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-01-08 10:24:05

0001 // Copyright (C) 2016 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
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 // header is automatically included in qglobal.h
0014 #pragma qt_no_master_include
0015 #pragma qt_class(QtLogging)
0016 #endif
0017 
0018 QT_BEGIN_NAMESPACE
0019 
0020 /*
0021   Forward declarations only.
0022 
0023   In order to use the qDebug() stream, you must #include<QDebug>
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 &copyContextFrom(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 #endif // QT_NO_DEBUG_STREAM
0138 
0139 #  if QT_CORE_REMOVED_SINCE(6, 10)
0140     QNoDebug noDebug() const noexcept;
0141 #  endif
0142     inline QNoDebug noDebug(...) const noexcept;    // in qdebug.h
0143 
0144 private:
0145     QMessageLogContext context;
0146 };
0147 
0148 #undef QT_MESSAGE_LOGGER_NORETURN
0149 
0150 #if !defined(QT_MESSAGELOGCONTEXT) && !defined(QT_NO_MESSAGELOGCONTEXT)
0151 #  if defined(QT_NO_DEBUG)
0152 #    define QT_NO_MESSAGELOGCONTEXT
0153 #  else
0154 #    define QT_MESSAGELOGCONTEXT
0155 #  endif
0156 #endif
0157 
0158 #ifdef QT_MESSAGELOGCONTEXT
0159   #define QT_MESSAGELOG_FILE static_cast<const char *>(__FILE__)
0160   #define QT_MESSAGELOG_LINE __LINE__
0161   #define QT_MESSAGELOG_FUNC static_cast<const char *>(Q_FUNC_INFO)
0162 #else
0163   #define QT_MESSAGELOG_FILE nullptr
0164   #define QT_MESSAGELOG_LINE 0
0165   #define QT_MESSAGELOG_FUNC nullptr
0166 #endif
0167 
0168 #define qDebug QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).debug
0169 #define qInfo QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).info
0170 #define qWarning QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).warning
0171 #define qCritical QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).critical
0172 #define qFatal QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).fatal
0173 
0174 Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(int code, const char *msg, ...);
0175 Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(const char *msg, ...);
0176 
0177 #define QT_NO_QDEBUG_MACRO while (false) QMessageLogger().noDebug
0178 
0179 #if defined(QT_NO_DEBUG_OUTPUT)
0180 #  undef qDebug
0181 #  define qDebug QT_NO_QDEBUG_MACRO
0182 #endif
0183 #if defined(QT_NO_INFO_OUTPUT)
0184 #  undef qInfo
0185 #  define qInfo QT_NO_QDEBUG_MACRO
0186 #endif
0187 #if defined(QT_NO_WARNING_OUTPUT)
0188 #  undef qWarning
0189 #  define qWarning QT_NO_QDEBUG_MACRO
0190 #  define qErrnoWarning QT_NO_QDEBUG_MACRO
0191 #endif
0192 
0193 Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context,
0194                                      const QString &message);
0195 
0196 typedef void (*QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &);
0197 Q_CORE_EXPORT QtMessageHandler qInstallMessageHandler(QtMessageHandler);
0198 
0199 Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern);
0200 Q_CORE_EXPORT QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context,
0201                                         const QString &buf);
0202 
0203 Q_DECL_COLD_FUNCTION
0204 Q_CORE_EXPORT QString qt_error_string(int errorCode = -1);
0205 
0206 QT_END_NAMESPACE
0207 #endif // QLOGGING_H