summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qlogging.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/global/qlogging.h')
-rw-r--r--src/corelib/global/qlogging.h161
1 files changed, 161 insertions, 0 deletions
diff --git a/src/corelib/global/qlogging.h b/src/corelib/global/qlogging.h
new file mode 100644
index 0000000000..c6edc7bc48
--- /dev/null
+++ b/src/corelib/global/qlogging.h
@@ -0,0 +1,161 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/qglobal.h>
+
+#ifndef QLOGGING_H
+#define QLOGGING_H
+
+#if 0
+// header is automatically included in qglobal.h
+#pragma qt_no_master_include
+#endif
+
+QT_BEGIN_HEADER
+QT_BEGIN_NAMESPACE
+
+/*
+ Forward declarations only.
+
+ In order to use the qDebug() stream, you must #include<QDebug>
+*/
+class QDebug;
+class QNoDebug;
+
+enum QtMsgType { QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg, QtSystemMsg = QtCriticalMsg };
+
+class QMessageLogContext
+{
+ Q_DISABLE_COPY(QMessageLogContext)
+public:
+ QMessageLogContext() : version(1), line(0), file(0), function(0) {}
+ Q_DECL_CONSTEXPR QMessageLogContext(const char *file, int line, const char *function)
+ : version(1), line(line), file(file), function(function) {}
+
+ int version;
+ int line;
+ const char *file;
+ const char *function;
+
+private:
+ friend class QMessageLogger;
+ friend class QDebug;
+};
+
+class Q_CORE_EXPORT QMessageLogger
+{
+ Q_DISABLE_COPY(QMessageLogger)
+public:
+ QMessageLogger() : context() {}
+ Q_DECL_CONSTEXPR QMessageLogger(const char *file, int line, const char *function)
+ : context(file, line, function) {}
+
+ void debug(const char *msg, ...)
+#if defined(Q_CC_GNU) && !defined(__INSURE__)
+ __attribute__ ((format (printf, 2, 3)))
+#endif
+ ;
+ void noDebug(const char *, ...)
+#if defined(Q_CC_GNU) && !defined(__INSURE__)
+ __attribute__ ((format (printf, 2, 3)))
+#endif
+ {}
+ void warning(const char *msg, ...)
+#if defined(Q_CC_GNU) && !defined(__INSURE__)
+ __attribute__ ((format (printf, 2, 3)))
+#endif
+ ;
+ void critical(const char *msg, ...)
+#if defined(Q_CC_GNU) && !defined(__INSURE__)
+ __attribute__ ((format (printf, 2, 3)))
+#endif
+ ;
+ void fatal(const char *msg, ...)
+#if defined(Q_CC_GNU) && !defined(__INSURE__)
+ __attribute__ ((format (printf, 2, 3)))
+#endif
+ ;
+
+#ifndef QT_NO_DEBUG_STREAM
+ QDebug debug();
+ QDebug warning();
+ QDebug critical();
+
+ QNoDebug noDebug();
+#endif // QT_NO_DEBUG_STREAM
+
+private:
+ QMessageLogContext context;
+};
+
+Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context, const char *buf);
+
+/*
+ qDebug, qWarning, qCritical, qFatal are redefined to automatically include context information
+ */
+#define qDebug QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debug
+#define qWarning QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).warning
+#define qCritical QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).critical
+#define qFatal QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).fatal
+
+#define QT_NO_QDEBUG_MACRO while (false) QMessageLogger().noDebug
+#define QT_NO_QWARNING_MACRO while (false) QMessageLogger().noDebug
+
+#ifdef QT_NO_DEBUG_OUTPUT
+# undef qDebug
+# define qDebug QT_NO_QDEBUG_MACRO
+#endif
+#ifdef QT_NO_WARNING_OUTPUT
+# undef qWarning
+# define qWarning QT_NO_QWARNING_MACRO
+#endif
+
+// deprecated. Use qInstallMessageHandler instead!
+typedef void (*QtMsgHandler)(QtMsgType, const char *);
+Q_CORE_EXPORT QtMsgHandler qInstallMsgHandler(QtMsgHandler);
+
+typedef void (*QMessageHandler)(QtMsgType, const QMessageLogContext &, const char *);
+Q_CORE_EXPORT QMessageHandler qInstallMessageHandler(QMessageHandler);
+
+QT_END_HEADER
+QT_END_NAMESPACE
+
+#endif // QLOGGING_H