Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qlogging.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QLOGGING_H
5#define QLOGGING_H
6
7#include <QtCore/qtclasshelpermacros.h>
8#include <QtCore/qtconfigmacros.h>
9#include <QtCore/qtcoreexports.h>
10#include <QtCore/qcontainerfwd.h>
11
12#if 0
13// header is automatically included in qglobal.h
14#pragma qt_no_master_include
15#pragma qt_class(QtLogging)
16#endif
17
19
20/*
21 Forward declarations only.
22
23 In order to use the qDebug() stream, you must #include<QDebug>
24*/
25class QDebug;
26class QNoDebug;
27
28
35#if QT_DEPRECATED_SINCE(6, 7)
36 QtSystemMsg Q_DECL_ENUMERATOR_DEPRECATED_X("Use QtCriticalMsg instead.") = QtCriticalMsg
37#endif
38};
39
42{
43 Q_DISABLE_COPY(QMessageLogContext)
44public:
45 static constexpr int CurrentVersion = 2;
46 constexpr QMessageLogContext() noexcept = default;
47 constexpr QMessageLogContext(const char *fileName, int lineNumber, const char *functionName, const char *categoryName) noexcept
48 : line(lineNumber), file(fileName), function(functionName), category(categoryName) {}
49
51 int line = 0;
52 const char *file = nullptr;
53 const char *function = nullptr;
54 const char *category = nullptr;
55
56private:
57 QMessageLogContext &copyContextFrom(const QMessageLogContext &logContext) noexcept;
58
60 friend class QMessageLogger;
61};
62
64
65#if defined(Q_CC_MSVC_ONLY)
66# define QT_MESSAGE_LOGGER_NORETURN
67#else
68# define QT_MESSAGE_LOGGER_NORETURN Q_NORETURN
69#endif
70
71class Q_CORE_EXPORT QMessageLogger
72{
73 Q_DISABLE_COPY(QMessageLogger)
74public:
75 constexpr QMessageLogger() : context() {}
76 constexpr QMessageLogger(const char *file, int line, const char *function)
77 : context(file, line, function, "default") {}
78 constexpr QMessageLogger(const char *file, int line, const char *function, const char *category)
79 : context(file, line, function, category) {}
80
81 void debug(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
82 void noDebug(const char *, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3)
83 {}
84 void info(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
86 void warning(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
88 void critical(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
90 void fatal(const char *msg, ...) const noexcept Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
91
92 typedef const QLoggingCategory &(*CategoryFunction)();
93
94 void debug(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
95 void debug(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
96 void info(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
97 void info(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
99 void warning(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
101 void warning(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
103 void critical(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
105 void critical(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
107 void fatal(const QLoggingCategory &cat, const char *msg, ...) const noexcept Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
109 void fatal(CategoryFunction catFunc, const char *msg, ...) const noexcept Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
110
111#ifndef QT_NO_DEBUG_STREAM
112 QDebug debug() const;
113 QDebug debug(const QLoggingCategory &cat) const;
114 QDebug debug(CategoryFunction catFunc) const;
115 QDebug info() const;
116 QDebug info(const QLoggingCategory &cat) const;
117 QDebug info(CategoryFunction catFunc) const;
119 QDebug warning() const;
121 QDebug warning(const QLoggingCategory &cat) const;
123 QDebug warning(CategoryFunction catFunc) const;
125 QDebug critical() const;
127 QDebug critical(const QLoggingCategory &cat) const;
129 QDebug critical(CategoryFunction catFunc) const;
131 QDebug fatal() const;
133 QDebug fatal(const QLoggingCategory &cat) const;
135 QDebug fatal(CategoryFunction catFunc) const;
136
137 QNoDebug noDebug() const noexcept;
138#endif // QT_NO_DEBUG_STREAM
139
140private:
142};
143
144#undef QT_MESSAGE_LOGGER_NORETURN
145
146#if !defined(QT_MESSAGELOGCONTEXT) && !defined(QT_NO_MESSAGELOGCONTEXT)
147# if defined(QT_NO_DEBUG)
148# define QT_NO_MESSAGELOGCONTEXT
149# else
150# define QT_MESSAGELOGCONTEXT
151# endif
152#endif
153
154#ifdef QT_MESSAGELOGCONTEXT
155 #define QT_MESSAGELOG_FILE static_cast<const char *>(__FILE__)
156 #define QT_MESSAGELOG_LINE __LINE__
157 #define QT_MESSAGELOG_FUNC static_cast<const char *>(Q_FUNC_INFO)
158#else
159 #define QT_MESSAGELOG_FILE nullptr
160 #define QT_MESSAGELOG_LINE 0
161 #define QT_MESSAGELOG_FUNC nullptr
162#endif
163
164#define qDebug QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).debug
165#define qInfo QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).info
166#define qWarning QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).warning
167#define qCritical QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).critical
168#define qFatal QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).fatal
169
170#define QT_NO_QDEBUG_MACRO while (false) QMessageLogger().noDebug
171
172#if defined(QT_NO_DEBUG_OUTPUT)
173# undef qDebug
174# define qDebug QT_NO_QDEBUG_MACRO
175#endif
176#if defined(QT_NO_INFO_OUTPUT)
177# undef qInfo
178# define qInfo QT_NO_QDEBUG_MACRO
179#endif
180#if defined(QT_NO_WARNING_OUTPUT)
181# undef qWarning
182# define qWarning QT_NO_QDEBUG_MACRO
183#endif
184
185Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context,
186 const QString &message);
187
188Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(int code, const char *msg, ...);
189Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(const char *msg, ...);
190
193
194Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern);
196 const QString &buf);
197
199Q_CORE_EXPORT QString qt_error_string(int errorCode = -1);
200
202#endif // QLOGGING_H
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
Definition qlogging.h:42
const char * category
Definition qlogging.h:54
constexpr QMessageLogContext() noexcept=default
const char * file
Definition qlogging.h:52
static constexpr int CurrentVersion
Definition qlogging.h:45
\inmodule QtCore
Definition qlogging.h:72
QDebug debug(CategoryFunction catFunc) const
constexpr QMessageLogger()
Constructs a default QMessageLogger.
Definition qlogging.h:75
Q_DECL_COLD_FUNCTION QDebug warning(CategoryFunction catFunc) const
constexpr QMessageLogger(const char *file, int line, const char *function)
Constructs a QMessageLogger to record log messages for file at line in function.
Definition qlogging.h:76
Q_DECL_COLD_FUNCTION QDebug critical(CategoryFunction catFunc) const
QDebug info(CategoryFunction catFunc) const
constexpr QMessageLogger(const char *file, int line, const char *function, const char *category)
Constructs a QMessageLogger to record category messages for file at line in function.
Definition qlogging.h:78
Q_DECL_COLD_FUNCTION QDebug fatal(CategoryFunction catFunc) const
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
const QLoggingCategory & category()
[1]
Combined button and popup list for selecting options.
static void * context
#define Q_DECL_ENUMERATOR_DEPRECATED_X(x)
#define Q_ATTRIBUTE_FORMAT_PRINTF(A, B)
#define Q_DECL_COLD_FUNCTION
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(int code, const char *msg,...)
#define QT_MESSAGE_LOGGER_NORETURN
Definition qlogging.h:68
Q_DECL_COLD_FUNCTION Q_CORE_EXPORT QString qt_error_string(int errorCode=-1)
Q_CORE_EXPORT QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, const QString &buf)
Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern)
Q_CORE_EXPORT QtMessageHandler qInstallMessageHandler(QtMessageHandler)
QtMsgType
Definition qlogging.h:29
@ QtCriticalMsg
Definition qlogging.h:32
@ QtInfoMsg
Definition qlogging.h:34
@ QtWarningMsg
Definition qlogging.h:31
@ QtFatalMsg
Definition qlogging.h:33
@ QtDebugMsg
Definition qlogging.h:30
Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context, const QString &message)
void(* QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &)
Definition qlogging.h:191
GLenum type
GLenum GLuint GLenum GLsizei const GLchar * buf
GLuint GLsizei const GLchar * message
QDebug warning(QAnyStringView fileName, int lineNumber)
QFile file
[0]
QHostInfo info
[0]