QXmpp Version: 1.10.0
QXmppLogger.h
1// SPDX-FileCopyrightText: 2009 Manjeet Dahiya <manjeetdahiya@gmail.com>
2// SPDX-FileCopyrightText: 2010 Jeremy Lainé <jeremy.laine@m4x.org>
3//
4// SPDX-License-Identifier: LGPL-2.1-or-later
5
6#ifndef QXMPPLOGGER_H
7#define QXMPPLOGGER_H
8
9#include "QXmppGlobal.h"
10
11#include <memory>
12
13#include <QObject>
14
15#ifdef QXMPP_LOGGABLE_TRACE
16#define qxmpp_loggable_trace(x) QString("%1(0x%2) %3").arg(metaObject()->className(), QString::number(reinterpret_cast<qint64>(this), 16), x)
17#else
18#define qxmpp_loggable_trace(x) (x)
19#endif
20
21class QXmppLoggerPrivate;
22
28class QXMPP_EXPORT QXmppLogger : public QObject
29{
30 Q_OBJECT
31 Q_FLAGS(MessageType MessageTypes)
32
33
34 Q_PROPERTY(QString logFilePath READ logFilePath WRITE setLogFilePath NOTIFY logFilePathChanged)
36 Q_PROPERTY(LoggingType loggingType READ loggingType WRITE setLoggingType NOTIFY loggingTypeChanged)
38 Q_PROPERTY(MessageTypes messageTypes READ messageTypes WRITE setMessageTypes NOTIFY messageTypesChanged)
39
40public:
43 NoLogging = 0,
44 FileLogging = 1,
45 StdoutLogging = 2,
46 SignalLogging = 4
47 };
48 Q_ENUM(LoggingType)
49
50
52 NoMessage = 0,
53 DebugMessage = 1,
54 InformationMessage = 2,
55 WarningMessage = 4,
56 ReceivedMessage = 8,
57 SentMessage = 16,
58 AnyMessage = 31
59 };
60 Q_DECLARE_FLAGS(MessageTypes, MessageType)
61
62 QXmppLogger(QObject *parent = nullptr);
63 ~QXmppLogger() override;
64
65 static QXmppLogger *getLogger();
66
67 // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
70 void setLoggingType(QXmppLogger::LoggingType type);
71 Q_SIGNAL void loggingTypeChanged();
72
73 // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
79 QString logFilePath();
80 void setLogFilePath(const QString &path);
81 Q_SIGNAL void logFilePathChanged();
82
83 // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
85 QXmppLogger::MessageTypes messageTypes();
86 void setMessageTypes(QXmppLogger::MessageTypes types);
87 Q_SIGNAL void messageTypesChanged();
88
89public Q_SLOTS:
90 virtual void setGauge(const QString &gauge, double value);
91 virtual void updateCounter(const QString &counter, qint64 amount);
92
93 void log(QXmppLogger::MessageType type, const QString &text);
94 void reopen();
95
96Q_SIGNALS:
98 void message(QXmppLogger::MessageType type, const QString &text);
99
100private:
101 static QXmppLogger *m_logger;
102 const std::unique_ptr<QXmppLoggerPrivate> d;
103};
104
108
109class QXMPP_EXPORT QXmppLoggable : public QObject
110{
111 Q_OBJECT
112
113public:
114 QXmppLoggable(QObject *parent = nullptr);
115
116protected:
118 void childEvent(QChildEvent *event) override;
120
124
125 void debug(const QString &message)
126 {
127 Q_EMIT logMessage(QXmppLogger::DebugMessage, qxmpp_loggable_trace(message));
128 }
129
133
134 void info(const QString &message)
135 {
136 Q_EMIT logMessage(QXmppLogger::InformationMessage, qxmpp_loggable_trace(message));
137 }
138
142
143 void warning(const QString &message)
144 {
145 Q_EMIT logMessage(QXmppLogger::WarningMessage, qxmpp_loggable_trace(message));
146 }
147
151
152 void logReceived(const QString &message)
153 {
154 Q_EMIT logMessage(QXmppLogger::ReceivedMessage, qxmpp_loggable_trace(message));
155 }
156
160
161 void logSent(const QString &message)
162 {
163 Q_EMIT logMessage(QXmppLogger::SentMessage, qxmpp_loggable_trace(message));
164 }
165
166Q_SIGNALS:
168 void setGauge(const QString &gauge, double value);
169
171 void logMessage(QXmppLogger::MessageType type, const QString &msg);
172
174 void updateCounter(const QString &counter, qint64 amount = 1);
175};
176
177Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppLogger::MessageTypes)
178#endif // QXMPPLOGGER_H
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:110
void logMessage(QXmppLogger::MessageType type, const QString &msg)
This signal is emitted to send logging messages.
void logSent(const QString &message)
Definition: QXmppLogger.h:161
void updateCounter(const QString &counter, qint64 amount=1)
Updates the given counter by amount.
void info(const QString &message)
Definition: QXmppLogger.h:134
void setGauge(const QString &gauge, double value)
Sets the given gauge to value.
void debug(const QString &message)
Definition: QXmppLogger.h:125
void warning(const QString &message)
Definition: QXmppLogger.h:143
void logReceived(const QString &message)
Definition: QXmppLogger.h:152
The QXmppLogger class represents a sink for logging messages.
Definition: QXmppLogger.h:29
Q_SIGNAL void messageTypesChanged()
QXmppLogger::LoggingType loggingType()
Returns the handler for logging messages.
Q_SIGNAL void loggingTypeChanged()
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:51
@ ReceivedMessage
Message received from server.
Definition: QXmppLogger.h:56
@ InformationMessage
Informational message.
Definition: QXmppLogger.h:54
@ SentMessage
Message sent to server.
Definition: QXmppLogger.h:57
@ DebugMessage
Debugging message.
Definition: QXmppLogger.h:53
@ WarningMessage
Warning message.
Definition: QXmppLogger.h:55
QString logFilePath()
LoggingType
This enum describes how log message are handled.
Definition: QXmppLogger.h:42
QXmppLogger::MessageTypes messageTypes()
Returns the types of messages to log.
Q_SIGNAL void logFilePathChanged()