QXmpp Version: 1.5.6
Loading...
Searching...
No Matches
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 <QObject>
12
13#ifdef QXMPP_LOGGABLE_TRACE
14#define qxmpp_loggable_trace(x) QString("%1(0x%2) %3").arg(metaObject()->className(), QString::number(reinterpret_cast<qint64>(this), 16), x)
15#else
16#define qxmpp_loggable_trace(x) (x)
17#endif
18
19class QXmppLoggerPrivate;
20
26class QXMPP_EXPORT QXmppLogger : public QObject
27{
28 Q_OBJECT
29 Q_FLAGS(MessageType MessageTypes)
30
31
32 Q_PROPERTY(QString logFilePath READ logFilePath WRITE setLogFilePath)
34 Q_PROPERTY(LoggingType loggingType READ loggingType WRITE setLoggingType)
36 Q_PROPERTY(MessageTypes messageTypes READ messageTypes WRITE setMessageTypes)
37
38public:
41 NoLogging = 0,
42 FileLogging = 1,
43 StdoutLogging = 2,
44 SignalLogging = 4
45 };
46 Q_ENUM(LoggingType)
47
48
50 NoMessage = 0,
51 DebugMessage = 1,
52 InformationMessage = 2,
53 WarningMessage = 4,
54 ReceivedMessage = 8,
55 SentMessage = 16,
56 AnyMessage = 31
57 };
58 Q_DECLARE_FLAGS(MessageTypes, MessageType)
59
60 QXmppLogger(QObject *parent = nullptr);
61 ~QXmppLogger() override;
62
63 static QXmppLogger *getLogger();
64
65 // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
68 void setLoggingType(QXmppLogger::LoggingType type);
69
70 // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
76 QString logFilePath();
77 void setLogFilePath(const QString &path);
78
79 // documentation needs to be here, see https://stackoverflow.com/questions/49192523/
81 QXmppLogger::MessageTypes messageTypes();
82 void setMessageTypes(QXmppLogger::MessageTypes types);
83
84public Q_SLOTS:
85 virtual void setGauge(const QString &gauge, double value);
86 virtual void updateCounter(const QString &counter, qint64 amount);
87
88 void log(QXmppLogger::MessageType type, const QString &text);
89 void reopen();
90
91Q_SIGNALS:
93 void message(QXmppLogger::MessageType type, const QString &text);
94
95private:
96 static QXmppLogger *m_logger;
97 QXmppLoggerPrivate *d;
98};
99
103
104class QXMPP_EXPORT QXmppLoggable : public QObject
105{
106 Q_OBJECT
107
108public:
109 QXmppLoggable(QObject *parent = nullptr);
110
111protected:
113 void childEvent(QChildEvent *event) override;
115
119
120 void debug(const QString &message)
121 {
122 Q_EMIT logMessage(QXmppLogger::DebugMessage, qxmpp_loggable_trace(message));
123 }
124
128
129 void info(const QString &message)
130 {
131 Q_EMIT logMessage(QXmppLogger::InformationMessage, qxmpp_loggable_trace(message));
132 }
133
137
138 void warning(const QString &message)
139 {
140 Q_EMIT logMessage(QXmppLogger::WarningMessage, qxmpp_loggable_trace(message));
141 }
142
146
147 void logReceived(const QString &message)
148 {
149 Q_EMIT logMessage(QXmppLogger::ReceivedMessage, qxmpp_loggable_trace(message));
150 }
151
155
156 void logSent(const QString &message)
157 {
158 Q_EMIT logMessage(QXmppLogger::SentMessage, qxmpp_loggable_trace(message));
159 }
160
161Q_SIGNALS:
163 void setGauge(const QString &gauge, double value);
164
166 void logMessage(QXmppLogger::MessageType type, const QString &msg);
167
169 void updateCounter(const QString &counter, qint64 amount = 1);
170};
171
172Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppLogger::MessageTypes)
173#endif // QXMPPLOGGER_H
The QXmppLoggable class represents a source of logging messages.
Definition QXmppLogger.h:105
void logMessage(QXmppLogger::MessageType type, const QString &msg)
This signal is emitted to send logging messages.
void logSent(const QString &message)
Definition QXmppLogger.h:156
void updateCounter(const QString &counter, qint64 amount=1)
Updates the given counter by amount.
void info(const QString &message)
Definition QXmppLogger.h:129
void setGauge(const QString &gauge, double value)
Sets the given gauge to value.
void debug(const QString &message)
Definition QXmppLogger.h:120
void warning(const QString &message)
Definition QXmppLogger.h:138
void logReceived(const QString &message)
Definition QXmppLogger.h:147
The QXmppLogger class represents a sink for logging messages.
Definition QXmppLogger.h:27
QXmppLogger::LoggingType loggingType()
Returns the handler for logging messages.
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:49
@ ReceivedMessage
Message received from server.
Definition QXmppLogger.h:54
@ InformationMessage
Informational message.
Definition QXmppLogger.h:52
@ SentMessage
Message sent to server.
Definition QXmppLogger.h:55
@ DebugMessage
Debugging message.
Definition QXmppLogger.h:51
@ WarningMessage
Warning message.
Definition QXmppLogger.h:53
QString logFilePath()
LoggingType
This enum describes how log message are handled.
Definition QXmppLogger.h:40
QXmppLogger::MessageTypes messageTypes()
Returns the types of messages to log.