~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/corelib/global/qlogging.h

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
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 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.
 
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 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.
 
24
**
 
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.
 
28
**
 
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.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#include <QtCore/qglobal.h>
 
43
 
 
44
#ifndef QLOGGING_H
 
45
#define QLOGGING_H
 
46
 
 
47
#if 0
 
48
// header is automatically included in qglobal.h
 
49
#pragma qt_no_master_include
 
50
#endif
 
51
 
 
52
QT_BEGIN_HEADER
 
53
QT_BEGIN_NAMESPACE
 
54
 
 
55
/*
 
56
  Forward declarations only.
 
57
 
 
58
  In order to use the qDebug() stream, you must #include<QDebug>
 
59
*/
 
60
class QDebug;
 
61
class QNoDebug;
 
62
 
 
63
enum QtMsgType { QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg, QtSystemMsg = QtCriticalMsg };
 
64
 
 
65
class QMessageLogContext
 
66
{
 
67
    Q_DISABLE_COPY(QMessageLogContext)
 
68
public:
 
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) {}
 
72
 
 
73
    void copy(const QMessageLogContext &logContext);
 
74
 
 
75
    int version;
 
76
    int line;
 
77
    const char *file;
 
78
    const char *function;
 
79
    const char *category;
 
80
 
 
81
private:
 
82
    friend class QMessageLogger;
 
83
    friend class QDebug;
 
84
};
 
85
 
 
86
class Q_CORE_EXPORT QMessageLogger
 
87
{
 
88
    Q_DISABLE_COPY(QMessageLogger)
 
89
public:
 
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) {}
 
95
 
 
96
    void debug(const char *msg, ...) const
 
97
#if defined(Q_CC_GNU) && !defined(__INSURE__)
 
98
    __attribute__ ((format (printf, 2, 3)))
 
99
#endif
 
100
    ;
 
101
    void noDebug(const char *, ...) const
 
102
#if defined(Q_CC_GNU) && !defined(__INSURE__)
 
103
    __attribute__ ((format (printf, 2, 3)))
 
104
#endif
 
105
    {}
 
106
    void warning(const char *msg, ...) const
 
107
#if defined(Q_CC_GNU) && !defined(__INSURE__)
 
108
    __attribute__ ((format (printf, 2, 3)))
 
109
#endif
 
110
    ;
 
111
    void critical(const char *msg, ...) const
 
112
#if defined(Q_CC_GNU) && !defined(__INSURE__)
 
113
    __attribute__ ((format (printf, 2, 3)))
 
114
#endif
 
115
    ;
 
116
 
 
117
#ifndef Q_CC_MSVC
 
118
    Q_NORETURN
 
119
#endif
 
120
    void fatal(const char *msg, ...) const Q_DECL_NOTHROW
 
121
#if defined(Q_CC_GNU) && !defined(__INSURE__)
 
122
    __attribute__ ((format (printf, 2, 3)))
 
123
#endif
 
124
    ;
 
125
 
 
126
#ifndef QT_NO_DEBUG_STREAM
 
127
    QDebug debug() const;
 
128
    QDebug warning() const;
 
129
    QDebug critical() const;
 
130
 
 
131
    QNoDebug noDebug() const Q_DECL_NOTHROW;
 
132
#endif // QT_NO_DEBUG_STREAM
 
133
 
 
134
private:
 
135
    QMessageLogContext context;
 
136
};
 
137
 
 
138
/*
 
139
  qDebug, qWarning, qCritical, qFatal are redefined to automatically include context information
 
140
 */
 
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
 
145
 
 
146
#define QT_NO_QDEBUG_MACRO while (false) QMessageLogger().noDebug
 
147
#define QT_NO_QWARNING_MACRO while (false) QMessageLogger().noDebug
 
148
 
 
149
#if defined(QT_NO_DEBUG_OUTPUT)
 
150
#  undef qDebug
 
151
#  define qDebug QT_NO_QDEBUG_MACRO
 
152
#endif
 
153
#if defined(QT_NO_WARNING_OUTPUT)
 
154
#  undef qWarning
 
155
#  define qWarning QT_NO_QWARNING_MACRO
 
156
#endif
 
157
 
 
158
Q_CORE_EXPORT void qt_message_output(QtMsgType, const QMessageLogContext &context,
 
159
                                     const QString &message);
 
160
 
 
161
Q_CORE_EXPORT void qErrnoWarning(int code, const char *msg, ...);
 
162
Q_CORE_EXPORT void qErrnoWarning(const char *msg, ...);
 
163
 
 
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);
 
167
#endif
 
168
 
 
169
typedef void (*QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &);
 
170
Q_CORE_EXPORT QtMessageHandler qInstallMessageHandler(QtMessageHandler);
 
171
 
 
172
Q_CORE_EXPORT void qSetMessagePattern(const QString &messagePattern);
 
173
 
 
174
QT_END_NAMESPACE
 
175
QT_END_HEADER
 
176
 
 
177
#endif // QLOGGING_H