1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtCore module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
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 QMessageLogContext() : version(1), line(0), file(0), function(0) {}
70 Q_DECL_CONSTEXPR QMessageLogContext(const char *fileName, int lineNumber,
71 const char *functionName)
72 : version(1), line(lineNumber), file(fileName), function(functionName) {}
80 friend class QMessageLogger;
84 class Q_CORE_EXPORT QMessageLogger
86 Q_DISABLE_COPY(QMessageLogger)
88 QMessageLogger() : context() {}
89 Q_DECL_CONSTEXPR QMessageLogger(const char *file, int line, const char *function)
90 : context(file, line, function) {}
92 void debug(const char *msg, ...)
93 #if defined(Q_CC_GNU) && !defined(__INSURE__)
94 __attribute__ ((format (printf, 2, 3)))
97 void noDebug(const char *, ...)
98 #if defined(Q_CC_GNU) && !defined(__INSURE__)
99 __attribute__ ((format (printf, 2, 3)))
102 void warning(const char *msg, ...)
103 #if defined(Q_CC_GNU) && !defined(__INSURE__)
104 __attribute__ ((format (printf, 2, 3)))
107 void critical(const char *msg, ...)
108 #if defined(Q_CC_GNU) && !defined(__INSURE__)
109 __attribute__ ((format (printf, 2, 3)))
112 void fatal(const char *msg, ...)
113 #if defined(Q_CC_GNU) && !defined(__INSURE__)
114 __attribute__ ((format (printf, 2, 3)))
118 #ifndef QT_NO_DEBUG_STREAM
124 #endif // QT_NO_DEBUG_STREAM
127 QMessageLogContext context;
131 qDebug, qWarning, qCritical, qFatal are redefined to automatically include context information
133 #define qDebug QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debug
134 #define qWarning QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).warning
135 #define qCritical QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).critical
136 #define qFatal QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).fatal
138 #define QT_NO_QDEBUG_MACRO while (false) QMessageLogger().noDebug
139 #define QT_NO_QWARNING_MACRO while (false) QMessageLogger().noDebug
141 #if defined(QT_NO_DEBUG_OUTPUT)
143 # define qDebug QT_NO_QDEBUG_MACRO
145 #if defined(QT_NO_WARNING_OUTPUT)
147 # define qWarning QT_NO_QWARNING_MACRO
150 Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context, const char *buf);
152 Q_CORE_EXPORT void qErrnoWarning(int code, const char *msg, ...);
153 Q_CORE_EXPORT void qErrnoWarning(const char *msg, ...);
155 // deprecated. Use qInstallMessageHandler instead!
156 typedef void (*QtMsgHandler)(QtMsgType, const char *);
157 Q_CORE_EXPORT QtMsgHandler qInstallMsgHandler(QtMsgHandler);
159 typedef void (*QMessageHandler)(QtMsgType, const QMessageLogContext &, const char *);
160 Q_CORE_EXPORT QMessageHandler qInstallMessageHandler(QMessageHandler);