QXmppLogger.h
/*
* Copyright (C) 2008-2014 The QXmpp developers
*
* Author:
* Manjeet Dahiya
* Jeremy Lainé
*
* Source:
* https://github.com/qxmpp-project/qxmpp
*
* This file is a part of QXmpp library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*/
#ifndef QXMPPLOGGER_H
#define QXMPPLOGGER_H
#include <QObject>
#include "QXmppGlobal.h"
#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_ENUMS(LoggingType)
Q_FLAGS(MessageType MessageTypes)
Q_PROPERTY(QString logFilePath READ logFilePath WRITE setLogFilePath)
Q_PROPERTY(LoggingType loggingType READ loggingType WRITE setLoggingType)
Q_PROPERTY(MessageTypes messageTypes READ messageTypes WRITE setMessageTypes)
public:
enum LoggingType
{
NoLogging = 0,
FileLogging = 1,
StdoutLogging = 2,
SignalLogging = 4
};
enum MessageType
{
NoMessage = 0,
DebugMessage = 1,
InformationMessage = 2,
WarningMessage = 4,
ReceivedMessage = 8,
SentMessage = 16,
AnyMessage = 31
};
Q_DECLARE_FLAGS(MessageTypes, MessageType)
QXmppLogger(QObject *parent = 0);
~QXmppLogger();
static QXmppLogger* getLogger();
QXmppLogger::LoggingType loggingType();
void setLoggingType(QXmppLogger::LoggingType type);
QString logFilePath();
void setLogFilePath(const QString &path);
QXmppLogger::MessageTypes messageTypes();
void setMessageTypes(QXmppLogger::MessageTypes types);
public 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();
signals:
void message(QXmppLogger::MessageType type, const QString &text);
private:
static QXmppLogger* m_logger;
QXmppLoggerPrivate *d;
};
class QXMPP_EXPORT QXmppLoggable : public QObject
{
Q_OBJECT
public:
QXmppLoggable(QObject *parent = 0);
protected:
virtual void childEvent(QChildEvent *event);
void debug(const QString &message)
{
emit logMessage(QXmppLogger::DebugMessage, qxmpp_loggable_trace(message));
}
void info(const QString &message)
{
emit logMessage(QXmppLogger::InformationMessage, qxmpp_loggable_trace(message));
}
void warning(const QString &message)
{
emit logMessage(QXmppLogger::WarningMessage, qxmpp_loggable_trace(message));
}
void logReceived(const QString &message)
{
emit logMessage(QXmppLogger::ReceivedMessage, qxmpp_loggable_trace(message));
}
void logSent(const QString &message)
{
emit logMessage(QXmppLogger::SentMessage, qxmpp_loggable_trace(message));
}
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
QXmppLogger::WarningMessage
Warning message.
Definition: QXmppLogger.h:70
QXmppLoggable::warning
void warning(const QString &message)
Definition: QXmppLogger.h:145
QXmppLogger::InformationMessage
Informational message.
Definition: QXmppLogger.h:69
QXmppLogger::MessageType
MessageType
This enum describes a type of log message.
Definition: QXmppLogger.h:65
QXmppLoggable
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:111
QXmppLogger::LoggingType
LoggingType
This enum describes how log message are handled.
Definition: QXmppLogger.h:56
QXmppLoggable::info
void info(const QString &message)
Definition: QXmppLogger.h:136
QXmppLoggable::logReceived
void logReceived(const QString &message)
Definition: QXmppLogger.h:154
QXmppLogger
The QXmppLogger class represents a sink for logging messages.
Definition: QXmppLogger.h:45
QXmppLoggable::debug
void debug(const QString &message)
Definition: QXmppLogger.h:127
QXmppLogger::DebugMessage
Debugging message.
Definition: QXmppLogger.h:68
QXmppLoggable::logSent
void logSent(const QString &message)
Definition: QXmppLogger.h:163
QXmppLogger::ReceivedMessage
Message received from server.
Definition: QXmppLogger.h:71
QXmppLogger::SentMessage
Message sent to server.
Definition: QXmppLogger.h:72