QXmpp Version: 0.9.3
QXmppLogger.h
1/*
2 * Copyright (C) 2008-2014 The QXmpp developers
3 *
4 * Author:
5 * Manjeet Dahiya
6 * Jeremy Lainé
7 *
8 * Source:
9 * https://github.com/qxmpp-project/qxmpp
10 *
11 * This file is a part of QXmpp library.
12 *
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 */
24
25
26#ifndef QXMPPLOGGER_H
27#define QXMPPLOGGER_H
28
29#include <QObject>
30
31#include "QXmppGlobal.h"
32
33#ifdef QXMPP_LOGGABLE_TRACE
34#define qxmpp_loggable_trace(x) QString("%1(0x%2) %3").arg(metaObject()->className(), QString::number(reinterpret_cast<qint64>(this), 16), x)
35#else
36#define qxmpp_loggable_trace(x) (x)
37#endif
38
39class QXmppLoggerPrivate;
40
44
45class QXMPP_EXPORT QXmppLogger : public QObject
46{
47 Q_OBJECT
48 Q_ENUMS(LoggingType)
49 Q_FLAGS(MessageType MessageTypes)
50 Q_PROPERTY(QString logFilePath READ logFilePath WRITE setLogFilePath)
51 Q_PROPERTY(LoggingType loggingType READ loggingType WRITE setLoggingType)
52 Q_PROPERTY(MessageTypes messageTypes READ messageTypes WRITE setMessageTypes)
53
54public:
57 {
58 NoLogging = 0,
59 FileLogging = 1,
60 StdoutLogging = 2,
61 SignalLogging = 4
62 };
63
66 {
67 NoMessage = 0,
68 DebugMessage = 1,
69 InformationMessage = 2,
70 WarningMessage = 4,
71 ReceivedMessage = 8,
72 SentMessage = 16,
73 AnyMessage = 31
74 };
75 Q_DECLARE_FLAGS(MessageTypes, MessageType)
76
77 QXmppLogger(QObject *parent = 0);
79
80 static QXmppLogger* getLogger();
81
82 QXmppLogger::LoggingType loggingType();
83 void setLoggingType(QXmppLogger::LoggingType type);
84
85 QString logFilePath();
86 void setLogFilePath(const QString &path);
87
88 QXmppLogger::MessageTypes messageTypes();
89 void setMessageTypes(QXmppLogger::MessageTypes types);
90
91public slots:
92 virtual void setGauge(const QString &gauge, double value);
93 virtual void updateCounter(const QString &counter, qint64 amount);
94
95 void log(QXmppLogger::MessageType type, const QString& text);
96 void reopen();
97
98signals:
100 void message(QXmppLogger::MessageType type, const QString &text);
101
102private:
103 static QXmppLogger* m_logger;
104 QXmppLoggerPrivate *d;
105};
106
110
111class QXMPP_EXPORT QXmppLoggable : public QObject
112{
113 Q_OBJECT
114
115public:
116 QXmppLoggable(QObject *parent = 0);
117
118protected:
120 virtual void childEvent(QChildEvent *event);
122
126
127 void debug(const QString &message)
128 {
129 emit logMessage(QXmppLogger::DebugMessage, qxmpp_loggable_trace(message));
130 }
131
135
136 void info(const QString &message)
137 {
138 emit logMessage(QXmppLogger::InformationMessage, qxmpp_loggable_trace(message));
139 }
140
144
145 void warning(const QString &message)
146 {
147 emit logMessage(QXmppLogger::WarningMessage, qxmpp_loggable_trace(message));
148 }
149
153
154 void logReceived(const QString &message)
155 {
156 emit logMessage(QXmppLogger::ReceivedMessage, qxmpp_loggable_trace(message));
157 }
158
162
163 void logSent(const QString &message)
164 {
165 emit logMessage(QXmppLogger::SentMessage, qxmpp_loggable_trace(message));
166 }
167
168signals:
170 void setGauge(const QString &gauge, double value);
171
173 void logMessage(QXmppLogger::MessageType type, const QString &msg);
174
176 void updateCounter(const QString &counter, qint64 amount = 1);
177};
178
179Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppLogger::MessageTypes)
180#endif // QXMPPLOGGER_H
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:112
void logMessage(QXmppLogger::MessageType type, const QString &msg)
This signal is emitted to send logging messages.
void logSent(const QString &message)
Definition: QXmppLogger.h:163
void updateCounter(const QString &counter, qint64 amount=1)
Updates the given counter by amount.
void info(const QString &message)
Definition: QXmppLogger.h:136
void setGauge(const QString &gauge, double value)
Sets the given gauge to value.
void debug(const QString &message)
Definition: QXmppLogger.h:127
void warning(const QString &message)
Definition: QXmppLogger.h:145
void logReceived(const QString &message)
Definition: QXmppLogger.h:154
The QXmppLogger class represents a sink for logging messages.
Definition: QXmppLogger.h:46
void message(QXmppLogger::MessageType type, const QString &text)
This signal is emitted whenever a log message is received.
MessageType
This enum describes a type of log message.
Definition: QXmppLogger.h:66
@ ReceivedMessage
Message received from server.
Definition: QXmppLogger.h:71
@ InformationMessage
Informational message.
Definition: QXmppLogger.h:69
@ SentMessage
Message sent to server.
Definition: QXmppLogger.h:72
@ DebugMessage
Debugging message.
Definition: QXmppLogger.h:68
@ WarningMessage
Warning message.
Definition: QXmppLogger.h:70
LoggingType
This enum describes how log message are handled.
Definition: QXmppLogger.h:57