Loading...
Searching...
No Matches
QXmppLogger.h
// SPDX-FileCopyrightText: 2009 Manjeet Dahiya <manjeetdahiya@gmail.com>
// SPDX-FileCopyrightText: 2010 Jeremy Lainé <jeremy.laine@m4x.org>
//
// SPDX-License-Identifier: LGPL-2.1-or-later
#ifndef QXMPPLOGGER_H
#define QXMPPLOGGER_H
#include "QXmppGlobal.h"
#include <memory>
#include <QObject>
#ifdef QXMPP_LOGGABLE_TRACE
#define qxmpp_loggable_trace(x) QString("%1(0x%2) %3").arg(metaObject()->className(), QString::number(reinterpret_cast<qint64>(this), 16), x)
#else
#define qxmpp_loggable_trace(x) (x)
#endif
class QXmppLoggerPrivate;
class QXMPP_EXPORT QXmppLogger : public QObject
{
Q_OBJECT
Q_FLAGS(MessageType MessageTypes)
Q_PROPERTY(QString logFilePath READ logFilePath WRITE setLogFilePath NOTIFY logFilePathChanged)
Q_PROPERTY(LoggingType loggingType READ loggingType WRITE setLoggingType NOTIFY loggingTypeChanged)
Q_PROPERTY(MessageTypes messageTypes READ messageTypes WRITE setMessageTypes NOTIFY messageTypesChanged)
public:
enum LoggingType {
NoLogging = 0,
FileLogging = 1,
StdoutLogging = 2,
SignalLogging = 4
};
Q_ENUM(LoggingType)
enum MessageType {
NoMessage = 0,
DebugMessage = 1,
InformationMessage = 2,
WarningMessage = 4,
ReceivedMessage = 8,
SentMessage = 16,
AnyMessage = 31
};
Q_DECLARE_FLAGS(MessageTypes, MessageType)
QXmppLogger(QObject *parent = nullptr);
~QXmppLogger() override;
static QXmppLogger *getLogger();
// documentation needs to be here, see https://stackoverflow.com/questions/49192523/
QXmppLogger::LoggingType loggingType();
void setLoggingType(QXmppLogger::LoggingType type);
Q_SIGNAL void loggingTypeChanged();
// documentation needs to be here, see https://stackoverflow.com/questions/49192523/
QString logFilePath();
void setLogFilePath(const QString &path);
Q_SIGNAL void logFilePathChanged();
// documentation needs to be here, see https://stackoverflow.com/questions/49192523/
QXmppLogger::MessageTypes messageTypes();
void setMessageTypes(QXmppLogger::MessageTypes types);
Q_SIGNAL void messageTypesChanged();
public Q_SLOTS:
virtual void setGauge(const QString &gauge, double value);
virtual void updateCounter(const QString &counter, qint64 amount);
void log(QXmppLogger::MessageType type, const QString &text);
void reopen();
Q_SIGNALS:
void message(QXmppLogger::MessageType type, const QString &text);
private:
static QXmppLogger *m_logger;
const std::unique_ptr<QXmppLoggerPrivate> d;
};
class QXMPP_EXPORT QXmppLoggable : public QObject
{
Q_OBJECT
public:
QXmppLoggable(QObject *parent = nullptr);
protected:
void childEvent(QChildEvent *event) override;
void debug(const QString &message)
{
Q_EMIT logMessage(QXmppLogger::DebugMessage, qxmpp_loggable_trace(message));
}
void info(const QString &message)
{
Q_EMIT logMessage(QXmppLogger::InformationMessage, qxmpp_loggable_trace(message));
}
void warning(const QString &message)
{
Q_EMIT logMessage(QXmppLogger::WarningMessage, qxmpp_loggable_trace(message));
}
void logReceived(const QString &message)
{
Q_EMIT logMessage(QXmppLogger::ReceivedMessage, qxmpp_loggable_trace(message));
}
void logSent(const QString &message)
{
Q_EMIT logMessage(QXmppLogger::SentMessage, qxmpp_loggable_trace(message));
}
Q_SIGNALS:
void setGauge(const QString &gauge, double value);
void logMessage(QXmppLogger::MessageType type, const QString &msg);
void updateCounter(const QString &counter, qint64 amount = 1);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppLogger::MessageTypes)
#endif // QXMPPLOGGER_H
QXmppLoggable
The QXmppLoggable class represents a source of logging messages.
Definition QXmppLogger.h:110
QXmppLoggable::logMessage
void logMessage(QXmppLogger::MessageType type, const QString &msg)
This signal is emitted to send logging messages.
QXmppLoggable::logSent
void logSent(const QString &message)
Definition QXmppLogger.h:161
QXmppLoggable::updateCounter
void updateCounter(const QString &counter, qint64 amount=1)
Updates the given counter by amount.
QXmppLoggable::info
void info(const QString &message)
Definition QXmppLogger.h:134
QXmppLoggable::setGauge
void setGauge(const QString &gauge, double value)
Sets the given gauge to value.
QXmppLoggable::debug
void debug(const QString &message)
Definition QXmppLogger.h:125
QXmppLoggable::warning
void warning(const QString &message)
Definition QXmppLogger.h:143
QXmppLoggable::logReceived
void logReceived(const QString &message)
Definition QXmppLogger.h:152
QXmppLogger
The QXmppLogger class represents a sink for logging messages.
Definition QXmppLogger.h:29
QXmppLogger::messageTypesChanged
Q_SIGNAL void messageTypesChanged()
QXmppLogger::loggingType
QXmppLogger::LoggingType loggingType()
Returns the handler for logging messages.
QXmppLogger::loggingTypeChanged
Q_SIGNAL void loggingTypeChanged()
QXmppLogger::message
void message(QXmppLogger::MessageType type, const QString &text)
This signal is emitted whenever a log message is received.
QXmppLogger::MessageType
MessageType
This enum describes a type of log message.
Definition QXmppLogger.h:51
QXmppLogger::ReceivedMessage
@ ReceivedMessage
Message received from server.
Definition QXmppLogger.h:56
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::messageTypes
QXmppLogger::MessageTypes messageTypes()
Returns the types of messages to log.
QXmppLogger::logFilePathChanged
Q_SIGNAL void logFilePathChanged()