QXmpp: QXmppLogger.h Source File

QXmpp Version: 1.14.3

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 <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
28 class 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:
42 enum LoggingType {
43 NoLogging = 0,
44 FileLogging = 1,
45 StdoutLogging = 2,
46 SignalLogging = 4
47 };
48 Q_ENUM(LoggingType)
49
50
51 enum MessageType {
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/
69 QXmppLogger::LoggingType loggingType();
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
89 Q_SLOT virtual void setGauge(const QString &gauge, double value);
90 Q_SLOT virtual void updateCounter(const QString &counter, qint64 amount);
91
92 Q_SLOT void log(QXmppLogger::MessageType type, const QString &text);
93 Q_SLOT void reopen();
94
96 Q_SIGNAL void message(QXmppLogger::MessageType type, const QString &text);
97
98private:
99 static QXmppLogger *m_logger;
100 const std::unique_ptr<QXmppLoggerPrivate> d;
101};
102
108 class QXMPP_EXPORT QXmppLoggable : public QObject
109{
110 Q_OBJECT
111
112public:
113 QXmppLoggable(QObject *parent = nullptr);
114
115protected:
117 void childEvent(QChildEvent *event) override;
119
121 void debug(const QString &message)
122 {
123 Q_EMIT logMessage(QXmppLogger::DebugMessage, qxmpp_loggable_trace(message));
124 }
125
127 void info(const QString &message)
128 {
129 Q_EMIT logMessage(QXmppLogger::InformationMessage, qxmpp_loggable_trace(message));
130 }
131
133 void warning(const QString &message)
134 {
135 Q_EMIT logMessage(QXmppLogger::WarningMessage, qxmpp_loggable_trace(message));
136 }
137
139 void logReceived(const QString &message)
140 {
141 Q_EMIT logMessage(QXmppLogger::ReceivedMessage, qxmpp_loggable_trace(message));
142 }
143
145 void logSent(const QString &message)
146 {
147 Q_EMIT logMessage(QXmppLogger::SentMessage, qxmpp_loggable_trace(message));
148 }
149
150public:
152 Q_SIGNAL void setGauge(const QString &gauge, double value);
153
155 Q_SIGNAL void logMessage(QXmppLogger::MessageType type, const QString &msg);
156
158 Q_SIGNAL void updateCounter(const QString &counter, qint64 amount = 1);
159};
160
161Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppLogger::MessageTypes)
162#endif // QXMPPLOGGER_H
QXmppLoggable::logSent
void logSent(const QString &message)
Logs a sent packet.
Definition QXmppLogger.h:145
QXmppLoggable::logMessage
Q_SIGNAL void logMessage(QXmppLogger::MessageType type, const QString &msg)
This signal is emitted to send logging messages.
QXmppLoggable::updateCounter
Q_SIGNAL void updateCounter(const QString &counter, qint64 amount=1)
Updates the given counter by amount.
QXmppLoggable::info
void info(const QString &message)
Logs an informational message.
Definition QXmppLogger.h:127
QXmppLoggable::QXmppLoggable
QXmppLoggable(QObject *parent=nullptr)
Definition QXmppLogger.cpp:57
QXmppLoggable::setGauge
Q_SIGNAL void setGauge(const QString &gauge, double value)
Sets the given gauge to value.
QXmppLoggable::debug
void debug(const QString &message)
Logs a debugging message.
Definition QXmppLogger.h:121
QXmppLoggable::warning
void warning(const QString &message)
Logs a warning message.
Definition QXmppLogger.h:133
QXmppLoggable::logReceived
void logReceived(const QString &message)
Logs a received packet.
Definition QXmppLogger.h:139
QXmppLogger
The QXmppLogger class represents a sink for logging messages.
Definition QXmppLogger.h:29
QXmppLogger::setLoggingType
void setLoggingType(QXmppLogger::LoggingType type)
Sets the handler for logging messages.
Definition QXmppLogger.cpp:139
QXmppLogger::setGauge
virtual Q_SLOT void setGauge(const QString &gauge, double value)
Definition QXmppLogger.cpp:210
QXmppLogger::messageTypesChanged
Q_SIGNAL void messageTypesChanged()
QXmppLogger::reopen
Q_SLOT void reopen()
If logging to a file, causes the file to be re-opened.
Definition QXmppLogger.cpp:257
QXmppLogger::loggingTypeChanged
Q_SIGNAL void loggingTypeChanged()
QXmppLogger::logFilePath
QString logFilePath
The path to which logging messages should be written.
Definition QXmppLogger.h:34
QXmppLogger::loggingType
QXmppLogger::LoggingType loggingType()
Returns the handler for logging messages.
QXmppLogger::log
Q_SLOT void log(QXmppLogger::MessageType type, const QString &text)
Add a logging message.
Definition QXmppLogger.cpp:179
QXmppLogger::setLogFilePath
void setLogFilePath(const QString &path)
Definition QXmppLogger.cpp:239
QXmppLogger::messageTypes
MessageTypes messageTypes
The types of messages to log.
Definition QXmppLogger.h:38
QXmppLogger::loggingType
LoggingType loggingType
The handler for logging messages.
Definition QXmppLogger.h:36
QXmppLogger::setMessageTypes
void setMessageTypes(QXmppLogger::MessageTypes types)
Sets the types of messages to log.
Definition QXmppLogger.cpp:162
QXmppLogger::MessageType
MessageType
This enum describes a type of log message.
Definition QXmppLogger.h:51
QXmppLogger::AnyMessage
@ AnyMessage
Any message type.
Definition QXmppLogger.h:58
QXmppLogger::ReceivedMessage
@ ReceivedMessage
Message received from server.
Definition QXmppLogger.h:56
QXmppLogger::NoMessage
@ NoMessage
No message type.
Definition QXmppLogger.h:52
QXmppLogger::InformationMessage
@ InformationMessage
Informational message.
Definition QXmppLogger.h:54
QXmppLogger::SentMessage
@ SentMessage
Message sent to server.
Definition QXmppLogger.h:57
QXmppLogger::DebugMessage
@ DebugMessage
Debugging message.
Definition QXmppLogger.h:53
QXmppLogger::WarningMessage
@ WarningMessage
Warning message.
Definition QXmppLogger.h:55
QXmppLogger::logFilePath
QString logFilePath()
QXmppLogger::LoggingType
LoggingType
This enum describes how log message are handled.
Definition QXmppLogger.h:42
QXmppLogger::FileLogging
@ FileLogging
Log messages are written to a file.
Definition QXmppLogger.h:44
QXmppLogger::NoLogging
@ NoLogging
Log messages are discarded.
Definition QXmppLogger.h:43
QXmppLogger::SignalLogging
@ SignalLogging
Log messages are emitted as a signal.
Definition QXmppLogger.h:46
QXmppLogger::StdoutLogging
@ StdoutLogging
Log messages are written to the standard output.
Definition QXmppLogger.h:45
QXmppLogger::updateCounter
virtual Q_SLOT void updateCounter(const QString &counter, qint64 amount)
Definition QXmppLogger.cpp:221
QXmppLogger::message
Q_SIGNAL void message(QXmppLogger::MessageType type, const QString &text)
This signal is emitted whenever a log message is received.
QXmppLogger::messageTypes
QXmppLogger::MessageTypes messageTypes()
Returns the types of messages to log.
QXmppLogger::QXmppLogger
QXmppLogger(QObject *parent=nullptr)
Definition QXmppLogger.cpp:111
QXmppLogger::logFilePathChanged
Q_SIGNAL void logFilePathChanged()