Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:07:28

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 QMessageLogContext
0042 {
0043     Q_DISABLE_COPY(QMessageLogContext)
0044 public:
0045     constexpr QMessageLogContext() noexcept = default;
0046     constexpr QMessageLogContext(const char *fileName, int lineNumber, const char *functionName, const char *categoryName) noexcept
0047         : line(lineNumber), file(fileName), function(functionName), category(categoryName) {}
0048 
0049     int version = 2;
0050     int line = 0;
0051     const char *file = nullptr;
0052     const char *function = nullptr;
0053     const char *category = nullptr;
0054 
0055 private:
0056     QMessageLogContext &copyContextFrom(const QMessageLogContext &logContext) noexcept;
0057 
0058     friend class QMessageLogger;
0059     friend class QDebug;
0060 };
0061 
0062 class QLoggingCategory;
0063 
0064 #if defined(Q_CC_MSVC_ONLY)
0065 #  define QT_MESSAGE_LOGGER_NORETURN
0066 #else
0067 #  define QT_MESSAGE_LOGGER_NORETURN Q_NORETURN
0068 #endif
0069 
0070 class Q_CORE_EXPORT QMessageLogger
0071 {
0072     Q_DISABLE_COPY(QMessageLogger)
0073 public:
0074     constexpr QMessageLogger() : context() {}
0075     constexpr QMessageLogger(const char *file, int line, const char *function)
0076         : context(file, line, function, "default") {}
0077     constexpr QMessageLogger(const char *file, int line, const char *function, const char *category)
0078         : context(file, line, function, category) {}
0079 
0080     void debug(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
0081     void noDebug(const char *, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3)
0082     {}
0083     void info(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
0084     Q_DECL_COLD_FUNCTION
0085     void warning(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
0086     Q_DECL_COLD_FUNCTION
0087     void critical(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
0088     QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION
0089     void fatal(const char *msg, ...) const noexcept Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
0090 
0091     typedef const QLoggingCategory &(*CategoryFunction)();
0092 
0093     void debug(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0094     void debug(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0095     void info(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0096     void info(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0097     Q_DECL_COLD_FUNCTION
0098     void warning(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0099     Q_DECL_COLD_FUNCTION
0100     void warning(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0101     Q_DECL_COLD_FUNCTION
0102     void critical(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0103     Q_DECL_COLD_FUNCTION
0104     void critical(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0105     QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION
0106     void fatal(const QLoggingCategory &cat, const char *msg, ...) const noexcept Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0107     QT_MESSAGE_LOGGER_NORETURN Q_DECL_COLD_FUNCTION
0108     void fatal(CategoryFunction catFunc, const char *msg, ...) const noexcept Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
0109 
0110 #ifndef QT_NO_DEBUG_STREAM
0111     QDebug debug() const;
0112     QDebug debug(const QLoggingCategory &cat) const;
0113     QDebug debug(CategoryFunction catFunc) const;
0114     QDebug info() const;
0115     QDebug info(const QLoggingCategory &cat) const;
0116     QDebug info(CategoryFunction catFunc) const;
0117     Q_DECL_COLD_FUNCTION
0118     QDebug warning() const;
0119     Q_DECL_COLD_FUNCTION
0120     QDebug warning(const QLoggingCategory &cat) const;
0121     Q_DECL_COLD_FUNCTION
0122     QDebug warning(CategoryFunction catFunc) const;
0123     Q_DECL_COLD_FUNCTION
0124     QDebug critical() const;
0125     Q_DECL_COLD_FUNCTION
0126     QDebug critical(const QLoggingCategory &cat) const;
0127     Q_DECL_COLD_FUNCTION
0128     QDebug critical(CategoryFunction catFunc) const;
0129     Q_DECL_COLD_FUNCTION
0130     QDebug fatal() const;
0131     Q_DECL_COLD_FUNCTION
0132     QDebug fatal(const QLoggingCategory &cat) const;
0133     Q_DECL_COLD_FUNCTION
0134     QDebug fatal(CategoryFunction catFunc) const;
0135 
0136     QNoDebug noDebug() const noexcept;
0137 #endif // QT_NO_DEBUG_STREAM
0138 
0139 private:
0140     QMessageLogContext context;
0141 };
0142 
0143 #undef QT_MESSAGE_LOGGER_NORETURN
0144 
0145 #if !defined(QT_MESSAGELOGCONTEXT) && !defined(QT_NO_MESSAGELOGCONTEXT)
0146 #  if defined(QT_NO_DEBUG)
0147 #    define QT_NO_MESSAGELOGCONTEXT
0148 #  else
0149 #    define QT_MESSAGELOGCONTEXT
0150 #  endif
0151 #endif
0152 
0153 #ifdef QT_MESSAGELOGCONTEXT
0154   #define QT_MESSAGELOG_FILE static_cast<const char *>(__FILE__)
0155   #define QT_MESSAGELOG_LINE __LINE__
0156   #define QT_MESSAGELOG_FUNC static_cast<const char *>(Q_FUNC_INFO)
0157 #else
0158   #define QT_MESSAGELOG_FILE nullptr
0159   #define QT_MESSAGELOG_LINE 0
0160   #define QT_MESSAGELOG_FUNC nullptr
0161 #endif
0162 
0163 #define qDebug QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).debug
0164 #define qInfo QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).info
0165 #define qWarning QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).warning
0166 #define qCritical QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).critical
0167 #define qFatal QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).fatal
0168 
0169 #define QT_NO_QDEBUG_MACRO while (false) QMessageLogger().noDebug
0170 
0171 #if defined(QT_NO_DEBUG_OUTPUT)
0172 #  undef qDebug
0173 #  define qDebug QT_NO_QDEBUG_MACRO
0174 #endif
0175 #if defined(QT_NO_INFO_OUTPUT)
0176 #  undef qInfo
0177 #  define qInfo QT_NO_QDEBUG_MACRO
0178 #endif
0179 #if defined(QT_NO_WARNING_OUTPUT)
0180 #  undef qWarning
0181 #  define qWarning QT_NO_QDEBUG_MACRO
0182 #endif
0183 
0184 Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context,
0185                                      const QString &message);
0186 
0187 Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(int code, const char *msg, ...);
0188 Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(const char *msg, ...);
0189 
0190 typedef void (*QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &);
0191 Q_CORE_EXPORT QtMessageHandler qInstallMessageHandler(QtMessageHandler);
0192 
0193 Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern);
0194 Q_CORE_EXPORT QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context,
0195                                         const QString &buf);
0196 
0197 Q_DECL_COLD_FUNCTION
0198 Q_CORE_EXPORT QString qt_error_string(int errorCode = -1);
0199 
0200 QT_END_NAMESPACE
0201 #endif // QLOGGING_H