QXmpp  Version:0.4.92
 All Classes Functions Enumerations Enumerator Properties Groups
QXmppLogger.h
1 /*
2  * Copyright (C) 2008-2011 The QXmpp developers
3  *
4  * Author:
5  * Manjeet Dahiya
6  * Jeremy LainĂ©
7  *
8  * Source:
9  * http://code.google.com/p/qxmpp
10  *
11  * This file is a part of QXmpp library.
12  *
13  * This library is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2.1 of the License, or (at your option) any later version.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * Lesser General Public License for more details.
22  *
23  */
24 
25 
26 #ifndef QXMPPLOGGER_H
27 #define QXMPPLOGGER_H
28 
29 #include <QObject>
30 
31 #include "QXmppGlobal.h"
32 
33 #ifdef QXMPP_LOGGABLE_TRACE
34 #define qxmpp_loggable_trace(x) QString("%1(0x%2) %3").arg(metaObject()->className(), QString::number(reinterpret_cast<qint64>(this), 16), x)
35 #else
36 #define qxmpp_loggable_trace(x) (x)
37 #endif
38 
39 class QXmppLoggerPrivate;
40 
44 
45 class QXMPP_EXPORT QXmppLogger : public QObject
46 {
47  Q_OBJECT
48  Q_ENUMS(LoggingType)
49  Q_FLAGS(MessageType MessageTypes)
50  Q_PROPERTY(QString logFilePath READ logFilePath WRITE setLogFilePath)
51  Q_PROPERTY(LoggingType loggingType READ loggingType WRITE setLoggingType)
52  Q_PROPERTY(MessageTypes messageTypes READ messageTypes WRITE setMessageTypes)
53 
54 public:
57  {
58  NoLogging = 0,
59  FileLogging = 1,
60  StdoutLogging = 2,
61  SignalLogging = 4,
62  };
63 
66  {
67  NoMessage = 0,
68  DebugMessage = 1,
69  InformationMessage = 2,
70  WarningMessage = 4,
71  ReceivedMessage = 8,
72  SentMessage = 16,
73  AnyMessage = 31,
74  };
75  Q_DECLARE_FLAGS(MessageTypes, MessageType)
76 
77  QXmppLogger(QObject *parent = 0);
78  ~QXmppLogger();
79 
80  static QXmppLogger* getLogger();
81 
82  QXmppLogger::LoggingType loggingType();
83  void setLoggingType(QXmppLogger::LoggingType type);
84 
85  QString logFilePath();
86  void setLogFilePath(const QString &path);
87 
88  QXmppLogger::MessageTypes messageTypes();
89  void setMessageTypes(QXmppLogger::MessageTypes types);
90 
91 public slots:
92  void log(QXmppLogger::MessageType type, const QString& text);
93  void reopen();
94 
95 signals:
97  void message(QXmppLogger::MessageType type, const QString &text);
98 
99 private:
100  static QXmppLogger* m_logger;
101  QXmppLoggerPrivate *d;
102 };
103 
107 
108 class QXMPP_EXPORT QXmppLoggable : public QObject
109 {
110  Q_OBJECT
111 
112 public:
113  QXmppLoggable(QObject *parent = 0);
114 
115 protected:
117  virtual void childEvent(QChildEvent *event);
119 
123 
124  void debug(const QString &message)
125  {
126  emit logMessage(QXmppLogger::DebugMessage, qxmpp_loggable_trace(message));
127  }
128 
132 
133  void info(const QString &message)
134  {
135  emit logMessage(QXmppLogger::InformationMessage, qxmpp_loggable_trace(message));
136  }
137 
141 
142  void warning(const QString &message)
143  {
144  emit logMessage(QXmppLogger::WarningMessage, qxmpp_loggable_trace(message));
145  }
146 
150 
151  void logReceived(const QString &message)
152  {
153  emit logMessage(QXmppLogger::ReceivedMessage, qxmpp_loggable_trace(message));
154  }
155 
159 
160  void logSent(const QString &message)
161  {
162  emit logMessage(QXmppLogger::SentMessage, qxmpp_loggable_trace(message));
163  }
164 
165 signals:
167  void logMessage(QXmppLogger::MessageType type, const QString &msg);
168 };
169 
170 Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppLogger::MessageTypes)
171 #endif // QXMPPLOGGER_H