1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtCore module of the Qt Toolkit.
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 Digia. For licensing terms and
14
** conditions see http://qt.digia.com/licensing. For further information
15
** use the contact form at http://qt.digia.com/contact-us.
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 2.1 as published by the Free Software
20
** Foundation and appearing in the file LICENSE.LGPL included in the
21
** packaging of this file. Please review the following information to
22
** ensure the GNU Lesser General Public License version 2.1 requirements
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25
** In addition, as a special exception, Digia gives you certain additional
26
** rights. These rights are described in the Digia Qt LGPL Exception
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29
** GNU General Public License Usage
30
** Alternatively, this file may be used under the terms of the GNU
31
** General Public License version 3.0 as published by the Free Software
32
** Foundation and appearing in the file LICENSE.GPL included in the
33
** packaging of this file. Please review the following information to
34
** ensure the GNU General Public License version 3.0 requirements will be
35
** met: http://www.gnu.org/copyleft/gpl.html.
40
****************************************************************************/
42
#include <QtCore/qglobal.h>
48
// header is automatically included in qglobal.h
49
#pragma qt_no_master_include
56
Forward declarations only.
58
In order to use the qDebug() stream, you must #include<QDebug>
63
enum QtMsgType { QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg, QtSystemMsg = QtCriticalMsg };
65
class QMessageLogContext
67
Q_DISABLE_COPY(QMessageLogContext)
69
Q_DECL_CONSTEXPR QMessageLogContext() : version(1), line(0), file(0), function(0), category(0) {}
70
Q_DECL_CONSTEXPR QMessageLogContext(const char *fileName, int lineNumber, const char *functionName, const char *categoryName)
71
: version(1), line(lineNumber), file(fileName), function(functionName), category(categoryName) {}
73
void copy(const QMessageLogContext &logContext);
82
friend class QMessageLogger;
86
class Q_CORE_EXPORT QMessageLogger
88
Q_DISABLE_COPY(QMessageLogger)
90
Q_DECL_CONSTEXPR QMessageLogger() : context() {}
91
Q_DECL_CONSTEXPR QMessageLogger(const char *file, int line, const char *function)
92
: context(file, line, function, "default") {}
93
Q_DECL_CONSTEXPR QMessageLogger(const char *file, int line, const char *function, const char *category)
94
: context(file, line, function, category) {}
96
void debug(const char *msg, ...) const
97
#if defined(Q_CC_GNU) && !defined(__INSURE__)
98
__attribute__ ((format (printf, 2, 3)))
101
void noDebug(const char *, ...) const
102
#if defined(Q_CC_GNU) && !defined(__INSURE__)
103
__attribute__ ((format (printf, 2, 3)))
106
void warning(const char *msg, ...) const
107
#if defined(Q_CC_GNU) && !defined(__INSURE__)
108
__attribute__ ((format (printf, 2, 3)))
111
void critical(const char *msg, ...) const
112
#if defined(Q_CC_GNU) && !defined(__INSURE__)
113
__attribute__ ((format (printf, 2, 3)))
120
void fatal(const char *msg, ...) const Q_DECL_NOTHROW
121
#if defined(Q_CC_GNU) && !defined(__INSURE__)
122
__attribute__ ((format (printf, 2, 3)))
126
#ifndef QT_NO_DEBUG_STREAM
127
QDebug debug() const;
128
QDebug warning() const;
129
QDebug critical() const;
131
QNoDebug noDebug() const Q_DECL_NOTHROW;
132
#endif // QT_NO_DEBUG_STREAM
135
QMessageLogContext context;
139
qDebug, qWarning, qCritical, qFatal are redefined to automatically include context information
141
#define qDebug QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debug
142
#define qWarning QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).warning
143
#define qCritical QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).critical
144
#define qFatal QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).fatal
146
#define QT_NO_QDEBUG_MACRO while (false) QMessageLogger().noDebug
147
#define QT_NO_QWARNING_MACRO while (false) QMessageLogger().noDebug
149
#if defined(QT_NO_DEBUG_OUTPUT)
151
# define qDebug QT_NO_QDEBUG_MACRO
153
#if defined(QT_NO_WARNING_OUTPUT)
155
# define qWarning QT_NO_QWARNING_MACRO
158
Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context,
159
const QString &message);
161
Q_CORE_EXPORT void qErrnoWarning(int code, const char *msg, ...);
162
Q_CORE_EXPORT void qErrnoWarning(const char *msg, ...);
164
#if QT_DEPRECATED_SINCE(5, 0)// deprecated. Use qInstallMessageHandler instead!
165
typedef void (*QtMsgHandler)(QtMsgType, const char *);
166
Q_CORE_EXPORT QT_DEPRECATED QtMsgHandler qInstallMsgHandler(QtMsgHandler);
169
typedef void (*QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &);
170
Q_CORE_EXPORT QtMessageHandler qInstallMessageHandler(QtMessageHandler);
172
Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern);