QtBase  v6.3.1
qlogging.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #include <QtCore/qglobal.h>
41 
42 #ifndef QLOGGING_H
43 #define QLOGGING_H
44 
45 #if 0
46 // header is automatically included in qglobal.h
47 #pragma qt_no_master_include
48 #endif
49 
51 
52 /*
53  Forward declarations only.
54 
55  In order to use the qDebug() stream, you must #include<QDebug>
56 */
57 class QDebug;
58 class QNoDebug;
59 
60 enum QtMsgType {
67 };
68 
70 {
72 public:
73  constexpr QMessageLogContext() noexcept = default;
74  constexpr QMessageLogContext(const char *fileName, int lineNumber, const char *functionName, const char *categoryName) noexcept
75  : line(lineNumber), file(fileName), function(functionName), category(categoryName) {}
76 
77  int version = 2;
78  int line = 0;
79  const char *file = nullptr;
80  const char *function = nullptr;
81  const char *category = nullptr;
82 
83 private:
84  QMessageLogContext &copyContextFrom(const QMessageLogContext &logContext) noexcept;
85 
86  friend class QMessageLogger;
87  friend class QDebug;
88 };
89 
90 class QLoggingCategory;
91 
92 class Q_CORE_EXPORT QMessageLogger
93 {
95 public:
96  constexpr QMessageLogger() : context() {}
97  constexpr QMessageLogger(const char *file, int line, const char *function)
98  : context(file, line, function, "default") {}
99  constexpr QMessageLogger(const char *file, int line, const char *function, const char *category)
101 
102  void debug(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
103  void noDebug(const char *, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3)
104  {}
105  void info(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
107  void warning(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
109  void critical(const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
110 
111  typedef const QLoggingCategory &(*CategoryFunction)();
112 
113  void debug(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
114  void debug(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
115  void info(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
116  void info(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
118  void warning(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
120  void warning(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
122  void critical(const QLoggingCategory &cat, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
124  void critical(CategoryFunction catFunc, const char *msg, ...) const Q_ATTRIBUTE_FORMAT_PRINTF(3, 4);
125 
126 #ifndef Q_CC_MSVC
127  Q_NORETURN
128 #endif
130  void fatal(const char *msg, ...) const noexcept Q_ATTRIBUTE_FORMAT_PRINTF(2, 3);
131 
132 #ifndef QT_NO_DEBUG_STREAM
133  QDebug debug() const;
134  QDebug debug(const QLoggingCategory &cat) const;
135  QDebug debug(CategoryFunction catFunc) const;
136  QDebug info() const;
137  QDebug info(const QLoggingCategory &cat) const;
138  QDebug info(CategoryFunction catFunc) const;
140  QDebug warning() const;
142  QDebug warning(const QLoggingCategory &cat) const;
144  QDebug warning(CategoryFunction catFunc) const;
146  QDebug critical() const;
148  QDebug critical(const QLoggingCategory &cat) const;
150  QDebug critical(CategoryFunction catFunc) const;
151 
152  QNoDebug noDebug() const noexcept;
153 #endif // QT_NO_DEBUG_STREAM
154 
155 private:
157 };
158 
159 #if !defined(QT_MESSAGELOGCONTEXT) && !defined(QT_NO_MESSAGELOGCONTEXT)
160 # if defined(QT_NO_DEBUG)
161 # define QT_NO_MESSAGELOGCONTEXT
162 # else
163 # define QT_MESSAGELOGCONTEXT
164 # endif
165 #endif
166 
167 #ifdef QT_MESSAGELOGCONTEXT
168  #define QT_MESSAGELOG_FILE static_cast<const char *>(__FILE__)
169  #define QT_MESSAGELOG_LINE __LINE__
170  #define QT_MESSAGELOG_FUNC static_cast<const char *>(Q_FUNC_INFO)
171 #else
172  #define QT_MESSAGELOG_FILE nullptr
173  #define QT_MESSAGELOG_LINE 0
174  #define QT_MESSAGELOG_FUNC nullptr
175 #endif
176 
177 #define qDebug QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).debug
178 #define qInfo QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).info
179 #define qWarning QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).warning
180 #define qCritical QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).critical
181 #define qFatal QMessageLogger(QT_MESSAGELOG_FILE, QT_MESSAGELOG_LINE, QT_MESSAGELOG_FUNC).fatal
182 
183 #define QT_NO_QDEBUG_MACRO while (false) QMessageLogger().noDebug
184 
185 #if defined(QT_NO_DEBUG_OUTPUT)
186 # undef qDebug
187 # define qDebug QT_NO_QDEBUG_MACRO
188 #endif
189 #if defined(QT_NO_INFO_OUTPUT)
190 # undef qInfo
191 # define qInfo QT_NO_QDEBUG_MACRO
192 #endif
193 #if defined(QT_NO_WARNING_OUTPUT)
194 # undef qWarning
195 # define qWarning QT_NO_QDEBUG_MACRO
196 #endif
197 
199  const QString &message);
200 
201 Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(int code, const char *msg, ...);
202 Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(const char *msg, ...);
203 
206 
207 Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern);
209  const QString &buf);
210 
212 #endif // QLOGGING_H
const char msg[]
Definition: arch.cpp:46
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
The QLoggingCategory class represents a category, or 'area' in the logging infrastructure.
The QMessageLogContext class provides additional information about a log message.
Definition: qlogging.h:70
const char * category
Definition: qlogging.h:81
constexpr QMessageLogContext() noexcept=default
const char * function
Definition: qlogging.h:80
const char * file
Definition: qlogging.h:79
The QMessageLogger class generates log messages.
Definition: qlogging.h:93
QDebug debug(CategoryFunction catFunc) const
constexpr QMessageLogger(const char *file, int line, const char *function, const char *category)
Definition: qlogging.h:99
constexpr QMessageLogger()
Definition: qlogging.h:96
Q_DECL_COLD_FUNCTION QDebug warning(CategoryFunction catFunc) const
constexpr QMessageLogger(const char *file, int line, const char *function)
Definition: qlogging.h:97
Q_DECL_COLD_FUNCTION QDebug critical(CategoryFunction catFunc) const
QDebug info(CategoryFunction catFunc) const
The QString class provides a Unicode character string.
Definition: qstring.h:388
const QLoggingCategory & category()
[1]
auto it unsigned count const
Definition: hb-iter.hh:848
backing_store_ptr info
[4]
Definition: jmemsys.h:161
default
Definition: devices.py:76
void
Definition: png.h:1080
#define Q_NORETURN
#define Q_DECL_COLD_FUNCTION
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction function
#define Q_DISABLE_COPY(Class)
Definition: qglobal.h:515
Q_CORE_EXPORT Q_DECL_COLD_FUNCTION void qErrnoWarning(int code, const char *msg,...)
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:60
@ QtCriticalMsg
Definition: qlogging.h:63
@ QtSystemMsg
Definition: qlogging.h:66
@ QtInfoMsg
Definition: qlogging.h:65
@ QtWarningMsg
Definition: qlogging.h:62
@ QtFatalMsg
Definition: qlogging.h:64
@ QtDebugMsg
Definition: qlogging.h:61
Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context, const QString &message)
void(* QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &)
Definition: qlogging.h:204
GLenum type
Definition: qopengl.h:270
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: qopengl.h:270
GLenum GLuint GLenum GLsizei const GLchar * buf
QFile file
[0]
Definition: inftrees.h:24