-
Notifications
You must be signed in to change notification settings - Fork 0
/
qxtlogger.h
219 lines (193 loc) · 11.2 KB
/
qxtlogger.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
/****************************************************************************
** Copyright (c) 2006 - 2011, the LibQxt project.
** See the Qxt AUTHORS file for a list of authors and copyright holders.
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in the
** documentation and/or other materials provided with the distribution.
** * Neither the name of the LibQxt project nor the
** names of its contributors may be used to endorse or promote products
** derived from this software without specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
** DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**
** <http://libqxt.org> <[email protected]>
*****************************************************************************/
#ifndef QXTLOGGER_H
#define QXTLOGGER_H
#include "qxtglobal.h"
#include <QObject>
#include <QVariant>
#include <QString>
#include <QStringList>
#include <QFlags>
class QxtLoggerPrivate;
class QxtLogStream;
class QxtLoggerEngine;
void QxtLoggerMessageHandler(QtMsgType type, const char *msg);
class QXT_CORE_EXPORT QxtLogger : public QObject
{
Q_OBJECT
QXT_DECLARE_PRIVATE(QxtLogger)
// Constructor & Destructor. Made private as QxtLogger is implemented as a singleton.
QxtLogger();
~QxtLogger();
public:
/*******************************************************************************
Defines for a bitmask to enable/disable logging levels.
Arranged in levels from (assumed) most verbose to most important.
*******************************************************************************/
enum LogLevel
{
NoLevels = 0, /**< No Levels enabled */
TraceLevel = 1 << 0, /**< The most verbose, flags trace() messages to be logged */
DebugLevel = 1 << 1, /**< Flags debug() messages to be logged */
InfoLevel = 1 << 2, /**< Flags info() messages to be logged */
WarningLevel = 1 << 3, /**< Flags warning() messages to be logged */
ErrorLevel = 1 << 4, /**< Flags error() messages to be logged */
CriticalLevel = 1 << 5, /**< Flags critical() messages to be logged */
FatalLevel = 1 << 6, /**< Flags fatal() messages to be logged */
WriteLevel = 1 << 7, /**< The most important, flags write() messages to be logged */
AllLevels = TraceLevel | DebugLevel | InfoLevel | WarningLevel | ErrorLevel | CriticalLevel | FatalLevel | WriteLevel /**< Enables all log levels */
};
Q_DECLARE_FLAGS(LogLevels, LogLevel)
/* Sone useful things */
static QString logLevelToString(LogLevel level);
static QxtLogger::LogLevel stringToLogLevel(const QString& level);
static QxtLogger &getInstance();
void initLoggerEngine(const QString& engineName);
void killLoggerEngine(const QString& engineName);
// Functions to install or remove QxtLogger as a handler for qDebug, qFatal, etc...
void installAsMessageHandler();
void removeAsMessageHandler();
//Functions for adding and removing loggers.
void addLoggerEngine(const QString& engineName, QxtLoggerEngine *engine);
void removeLoggerEngine(const QString& engineName);
void removeLoggerEngine(QxtLoggerEngine *engine);
QxtLoggerEngine* takeLoggerEngine(const QString& engineName);
QxtLoggerEngine* engine(const QString& engineName);
// Functions for checking loggers.
QStringList allLoggerEngines() const;
QStringList allEnabledLoggerEngines() const;
QStringList allEnabledLoggerEngines(LogLevel level) const;
QStringList allDisabledLoggerEngines() const;
bool isLogLevelEnabled(const QString& engineName, LogLevel level) const;
bool isLoggerEngine(const QString& engineName) const;
bool isLoggerEngineEnabled(const QString& engineName) const;
/*******************************************************************************
Streaming!
*******************************************************************************/
QxtLogStream stream(LogLevel level);
QxtLogStream trace();
QxtLogStream debug();
QxtLogStream info();
QxtLogStream warning();
QxtLogStream error();
QxtLogStream critical();
QxtLogStream fatal();
QxtLogStream write();
/* stream overloads */
QxtLogger* operator->();
QxtLogStream operator()(const QString &logTarget);
/*******************************************************************************
Log Level enable and disable: The 1-param functions enable/disable that level on
ALL log engines. The 2-param functions enable/disable that on a named logger.
*******************************************************************************/
void enableLogLevels(LogLevels levels);
void enableLogLevels(const QString& engineName, LogLevels levels);
void enableAllLogLevels();
void enableAllLogLevels(const QString& engineName);
void enableLoggerEngine(const QString& engineName);
void disableLogLevels(LogLevels levels);
void disableLogLevels(const QString& engineName, LogLevels levels);
void disableAllLogLevels();
void disableAllLogLevels(const QString& engineName);
void disableLoggerEngine(const QString& engineName);
void setMinimumLevel(LogLevel level);
void setMinimumLevel(const QString& engineName, LogLevel level);
public Q_SLOTS:
/*******************************************************************************
Logging Functions: what the QxtLogger is all about.
*******************************************************************************/
void info(const QVariant& message, const QVariant& msg1 = QVariant(),
const QVariant& msg2 = QVariant(), const QVariant& msg3 = QVariant(),
const QVariant& msg4 = QVariant(), const QVariant& msg5 = QVariant(),
const QVariant& msg6 = QVariant(), const QVariant& msg7 = QVariant(),
const QVariant& msg8 = QVariant(), const QVariant& msg9 = QVariant());
void trace(const QVariant& message, const QVariant& msg1 = QVariant(),
const QVariant& msg2 = QVariant(), const QVariant& msg3 = QVariant(),
const QVariant& msg4 = QVariant(), const QVariant& msg5 = QVariant(),
const QVariant& msg6 = QVariant(), const QVariant& msg7 = QVariant(),
const QVariant& msg8 = QVariant(), const QVariant& msg9 = QVariant());
void warning(const QVariant& message, const QVariant& msg1 = QVariant(),
const QVariant& msg2 = QVariant(), const QVariant& msg3 = QVariant(),
const QVariant& msg4 = QVariant(), const QVariant& msg5 = QVariant(),
const QVariant& msg6 = QVariant(), const QVariant& msg7 = QVariant(),
const QVariant& msg8 = QVariant(), const QVariant& msg9 = QVariant());
void error(const QVariant& message, const QVariant& msg1 = QVariant(),
const QVariant& msg2 = QVariant(), const QVariant& msg3 = QVariant(),
const QVariant& msg4 = QVariant(), const QVariant& msg5 = QVariant(),
const QVariant& msg6 = QVariant(), const QVariant& msg7 = QVariant(),
const QVariant& msg8 = QVariant(), const QVariant& msg9 = QVariant());
void debug(const QVariant& message, const QVariant& msg1 = QVariant(),
const QVariant& msg2 = QVariant(), const QVariant& msg3 = QVariant(),
const QVariant& msg4 = QVariant(), const QVariant& msg5 = QVariant(),
const QVariant& msg6 = QVariant(), const QVariant& msg7 = QVariant(),
const QVariant& msg8 = QVariant(), const QVariant& msg9 = QVariant());
void critical(const QVariant& message, const QVariant& msg1 = QVariant(),
const QVariant& msg2 = QVariant(), const QVariant& msg3 = QVariant(),
const QVariant& msg4 = QVariant(), const QVariant& msg5 = QVariant(),
const QVariant& msg6 = QVariant(), const QVariant& msg7 = QVariant(),
const QVariant& msg8 = QVariant(), const QVariant& msg9 = QVariant());
void fatal(const QVariant& message, const QVariant& msg1 = QVariant(),
const QVariant& msg2 = QVariant(), const QVariant& msg3 = QVariant(),
const QVariant& msg4 = QVariant(), const QVariant& msg5 = QVariant(),
const QVariant& msg6 = QVariant(), const QVariant& msg7 = QVariant(),
const QVariant& msg8 = QVariant(), const QVariant& msg9 = QVariant());
void write(const QVariant& message, const QVariant& msg1 = QVariant(),
const QVariant& msg2 = QVariant(), const QVariant& msg3 = QVariant(),
const QVariant& msg4 = QVariant(), const QVariant& msg5 = QVariant(),
const QVariant& msg6 = QVariant(), const QVariant& msg7 = QVariant(),
const QVariant& msg8 = QVariant(), const QVariant& msg9 = QVariant());
/*******************************************************************************
Logging Functions in QList<QVariant> form.
*******************************************************************************/
void info(const QList<QVariant>& args);
void trace(const QList<QVariant>& args);
void warning(const QList<QVariant>& args);
void error(const QList<QVariant>& args);
void debug(const QList<QVariant>& args);
void critical(const QList<QVariant>& args);
void fatal(const QList<QVariant>& args);
void write(const QList<QVariant>& args);
/*******************************************************************************
And now a generic Logging function
*******************************************************************************/
void log(LogLevel level, const QList<QVariant>& args); // old logger
void Log(const QString &logTarget, const QList<QVariant>& args);
Q_SIGNALS:
void loggerEngineAdded(const QString& engineName);
void loggerEngineRemoved(const QString& engineName);
void loggerEngineEnabled(const QString& engineName);
void loggerEngineDisabled(const QString& engineName);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QxtLogger::LogLevels)
Q_DECLARE_METATYPE(QxtLogger::LogLevel)
Q_DECLARE_METATYPE(QxtLogger::LogLevels)
#define qxtLog QxtLogger::getInstance()
#include "qxtlogstream.h"
#endif // QXTLOGGER_H