QXmpp  Version:0.9.3
QXmppLogger.h
00001 /*
00002  * Copyright (C) 2008-2014 The QXmpp developers
00003  *
00004  * Author:
00005  *  Manjeet Dahiya
00006  *  Jeremy Lainé
00007  *
00008  * Source:
00009  *  https://github.com/qxmpp-project/qxmpp
00010  *
00011  * This file is a part of QXmpp library.
00012  *
00013  * This library is free software; you can redistribute it and/or
00014  * modify it under the terms of the GNU Lesser General Public
00015  * License as published by the Free Software Foundation; either
00016  * version 2.1 of the License, or (at your option) any later version.
00017  *
00018  * This library is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  * Lesser General Public License for more details.
00022  *
00023  */
00024 
00025 
00026 #ifndef QXMPPLOGGER_H
00027 #define QXMPPLOGGER_H
00028 
00029 #include <QObject>
00030 
00031 #include "QXmppGlobal.h"
00032 
00033 #ifdef QXMPP_LOGGABLE_TRACE
00034 #define qxmpp_loggable_trace(x) QString("%1(0x%2) %3").arg(metaObject()->className(), QString::number(reinterpret_cast<qint64>(this), 16), x)
00035 #else
00036 #define qxmpp_loggable_trace(x) (x)
00037 #endif
00038 
00039 class QXmppLoggerPrivate;
00040 
00044 
00045 class QXMPP_EXPORT QXmppLogger : public QObject
00046 {
00047     Q_OBJECT
00048     Q_ENUMS(LoggingType)
00049     Q_FLAGS(MessageType MessageTypes)
00050     Q_PROPERTY(QString logFilePath READ logFilePath WRITE setLogFilePath)
00051     Q_PROPERTY(LoggingType loggingType READ loggingType WRITE setLoggingType)
00052     Q_PROPERTY(MessageTypes messageTypes READ messageTypes WRITE setMessageTypes)
00053 
00054 public:
00056     enum LoggingType
00057     {
00058         NoLogging = 0,      
00059         FileLogging = 1,    
00060         StdoutLogging = 2,  
00061         SignalLogging = 4   
00062     };
00063 
00065     enum MessageType
00066     {
00067         NoMessage = 0,          
00068         DebugMessage = 1,       
00069         InformationMessage = 2, 
00070         WarningMessage = 4,     
00071         ReceivedMessage = 8,    
00072         SentMessage = 16,       
00073         AnyMessage = 31         
00074     };
00075     Q_DECLARE_FLAGS(MessageTypes, MessageType)
00076 
00077     QXmppLogger(QObject *parent = 0);
00078     ~QXmppLogger();
00079 
00080     static QXmppLogger* getLogger();
00081 
00082     QXmppLogger::LoggingType loggingType();
00083     void setLoggingType(QXmppLogger::LoggingType type);
00084 
00085     QString logFilePath();
00086     void setLogFilePath(const QString &path);
00087 
00088     QXmppLogger::MessageTypes messageTypes();
00089     void setMessageTypes(QXmppLogger::MessageTypes types);
00090 
00091 public slots:
00092     virtual void setGauge(const QString &gauge, double value);
00093     virtual void updateCounter(const QString &counter, qint64 amount);
00094 
00095     void log(QXmppLogger::MessageType type, const QString& text);
00096     void reopen();
00097 
00098 signals:
00100     void message(QXmppLogger::MessageType type, const QString &text);
00101 
00102 private:
00103     static QXmppLogger* m_logger;
00104     QXmppLoggerPrivate *d;
00105 };
00106 
00110 
00111 class QXMPP_EXPORT QXmppLoggable : public QObject
00112 {
00113     Q_OBJECT
00114 
00115 public:
00116     QXmppLoggable(QObject *parent = 0);
00117 
00118 protected:
00120     virtual void childEvent(QChildEvent *event);
00122 
00126 
00127     void debug(const QString &message)
00128     {
00129         emit logMessage(QXmppLogger::DebugMessage, qxmpp_loggable_trace(message));
00130     }
00131 
00135 
00136     void info(const QString &message)
00137     {
00138         emit logMessage(QXmppLogger::InformationMessage, qxmpp_loggable_trace(message));
00139     }
00140 
00144 
00145     void warning(const QString &message)
00146     {
00147         emit logMessage(QXmppLogger::WarningMessage, qxmpp_loggable_trace(message));
00148     }
00149 
00153 
00154     void logReceived(const QString &message)
00155     {
00156         emit logMessage(QXmppLogger::ReceivedMessage, qxmpp_loggable_trace(message));
00157     }
00158 
00162 
00163     void logSent(const QString &message)
00164     {
00165         emit logMessage(QXmppLogger::SentMessage, qxmpp_loggable_trace(message));
00166     }
00167 
00168 signals:
00170     void setGauge(const QString &gauge, double value);
00171 
00173     void logMessage(QXmppLogger::MessageType type, const QString &msg);
00174 
00176     void updateCounter(const QString &counter, qint64 amount = 1);
00177 };
00178 
00179 Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppLogger::MessageTypes)
00180 #endif // QXMPPLOGGER_H
 All Classes Functions Enumerations Enumerator Properties