QXmpp  Version:0.9.1
QXmppLogger.h
1 /*
2  * Copyright (C) 2008-2014 The QXmpp developers
3  *
4  * Author:
5  * Manjeet Dahiya
6  * Jeremy LainĂ©
7  *
8  * Source:
9  * https://github.com/qxmpp-project/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  virtual void setGauge(const QString &gauge, double value);
93  virtual void updateCounter(const QString &counter, qint64 amount);
94 
95  void log(QXmppLogger::MessageType type, const QString& text);
96  void reopen();
97 
98 signals:
100  void message(QXmppLogger::MessageType type, const QString &text);
101 
102 private:
103  static QXmppLogger* m_logger;
104  QXmppLoggerPrivate *d;
105 };
106 
110 
111 class QXMPP_EXPORT QXmppLoggable : public QObject
112 {
113  Q_OBJECT
114 
115 public:
116  QXmppLoggable(QObject *parent = 0);
117 
118 protected:
120  virtual void childEvent(QChildEvent *event);
122 
126 
127  void debug(const QString &message)
128  {
129  emit logMessage(QXmppLogger::DebugMessage, qxmpp_loggable_trace(message));
130  }
131 
135 
136  void info(const QString &message)
137  {
138  emit logMessage(QXmppLogger::InformationMessage, qxmpp_loggable_trace(message));
139  }
140 
144 
145  void warning(const QString &message)
146  {
147  emit logMessage(QXmppLogger::WarningMessage, qxmpp_loggable_trace(message));
148  }
149 
153 
154  void logReceived(const QString &message)
155  {
156  emit logMessage(QXmppLogger::ReceivedMessage, qxmpp_loggable_trace(message));
157  }
158 
162 
163  void logSent(const QString &message)
164  {
165  emit logMessage(QXmppLogger::SentMessage, qxmpp_loggable_trace(message));
166  }
167 
168 signals:
170  void setGauge(const QString &gauge, double value);
171 
173  void logMessage(QXmppLogger::MessageType type, const QString &msg);
174 
176  void updateCounter(const QString &counter, qint64 amount = 1);
177 };
178 
179 Q_DECLARE_OPERATORS_FOR_FLAGS(QXmppLogger::MessageTypes)
180 #endif // QXMPPLOGGER_H
Informational message.
Definition: QXmppLogger.h:69
void warning(const QString &message)
Definition: QXmppLogger.h:145
Message received from server.
Definition: QXmppLogger.h:71
Debugging message.
Definition: QXmppLogger.h:68
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:111
LoggingType
This enum describes how log message are handled.
Definition: QXmppLogger.h:56
Warning message.
Definition: QXmppLogger.h:70
Message sent to server.
Definition: QXmppLogger.h:72
void info(const QString &message)
Definition: QXmppLogger.h:136
void logReceived(const QString &message)
Definition: QXmppLogger.h:154
The QXmppLogger class represents a sink for logging messages.
Definition: QXmppLogger.h:45
MessageType
This enum describes a type of log message.
Definition: QXmppLogger.h:65
void debug(const QString &message)
Definition: QXmppLogger.h:127
void logSent(const QString &message)
Definition: QXmppLogger.h:163