QXmppLogger.h

    00001 /*
    00002  * Copyright (C) 2008-2011 The QXmpp developers
    00003  *
    00004  * Author:
    00005  *  Manjeet Dahiya
    00006  *  Jeremy Lainé
    00007  *
    00008  * Source:
    00009  *  http://code.google.com/p/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 #ifdef QXMPP_LOGGABLE_TRACE
    00032 #define qxmpp_loggable_trace(x) QString("%1(0x%2) %3").arg(metaObject()->className(), QString::number(reinterpret_cast<qint64>(this), 16), x)
    00033 #else
    00034 #define qxmpp_loggable_trace(x) (x)
    00035 #endif
    00036
    00037 class QXmppLoggerPrivate;
    00038
    00042
    00043 class QXmppLogger : public QObject
    00044 {
    00045     Q_OBJECT
    00046     Q_ENUMS(LoggingType)
    00047     Q_FLAGS(MessageType MessageTypes)
    00048     Q_PROPERTY(QString logFilePath READ logFilePath WRITE setLogFilePath)
    00049     Q_PROPERTY(LoggingType loggingType READ loggingType WRITE setLoggingType)
    00050     Q_PROPERTY(MessageTypes messageTypes READ messageTypes WRITE setMessageTypes)
    00051
    00052 public:
    00054     enum LoggingType
    00055     {
    00056         NoLogging = 0,
    00057         FileLogging = 1,
    00058         StdoutLogging = 2,
    00059         SignalLogging = 4,
    00060     };
    00061
    00063     enum MessageType
    00064     {
    00065         NoMessage = 0,
    00066         DebugMessage = 1,
    00067         InformationMessage = 2,
    00068         WarningMessage = 4,
    00069         ReceivedMessage = 8,
    00070         SentMessage = 16,
    00071         AnyMessage = 31,
    00072     };
    00073     Q_DECLARE_FLAGS(MessageTypes, MessageType)
    00074
    00075     QXmppLogger(QObject *parent = 0);
    00076     ~QXmppLogger();
    00077
    00078     static QXmppLogger* getLogger();
    00079
    00080     QXmppLogger::LoggingType loggingType();
    00081     void setLoggingType(QXmppLogger::LoggingType type);
    00082
    00083     QString logFilePath();
    00084     void setLogFilePath(const QString &path);
    00085
    00086     QXmppLogger::MessageTypes messageTypes();
    00087     void setMessageTypes(QXmppLogger::MessageTypes types);
    00088
    00089 public slots:
    00090     void log(QXmppLogger::MessageType type, const QString& text);
    00091     void reopen();
    00092
    00093 signals:
    00095     void message(QXmppLogger::MessageType type, const QString &text);
    00096
    00097 private:
    00098     static QXmppLogger* m_logger;
    00099     QXmppLoggerPrivate *d;
    00100 };
    00101
    00105
    00106 class QXmppLoggable : public QObject
    00107 {
    00108     Q_OBJECT
    00109
    00110 public:
    00111     QXmppLoggable(QObject *parent = 0);
    00112
    00113 protected:
    00115     virtual void childEvent(QChildEvent *event);
    00117
    00121
    00122     void debug(const QString &message)
    00123     {
    00124         emit logMessage(QXmppLogger::DebugMessage, qxmpp_loggable_trace(message));
    00125     }
    00126
    00130
    00131     void info(const QString &message)
    00132     {
    00133         emit logMessage(QXmppLogger::InformationMessage, qxmpp_loggable_trace(message));
    00134     }
    00135
    00139
    00140     void warning(const QString &message)
    00141     {
    00142         emit logMessage(QXmppLogger::WarningMessage, qxmpp_loggable_trace(message));
    00143     }
    00144
    00148
    00149     void logReceived(const QString &message)
    00150     {
    00151         emit logMessage(QXmppLogger::ReceivedMessage, qxmpp_loggable_trace(message));
    00152     }
    00153
    00157
    00158     void logSent(const QString &message)
    00159     {
    00160         emit logMessage(QXmppLogger::SentMessage, qxmpp_loggable_trace(message));
    00161     }
    00162
    00163 signals:
    00165     void logMessage(QXmppLogger::MessageType type, const QString &msg);
    00166 };
    00167
    00168 Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppLogger::MessageTypes)
    00169 #endif // QXMPPLOGGER_H

All Classes Functions Enumerations Enumerator Properties