aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-03-08 20:08:05 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-03-08 20:08:05 +0000
commitfad04899470294d98233cfc27c6c18f82990c7ac (patch)
treeac13c50c6261310e3a0b66435614bd7c3235e453 /source
parentd1765ee554d21cb947eed3fbf1aa9073ff962443 (diff)
downloadqxmpp-fad04899470294d98233cfc27c6c18f82990c7ac.tar.gz
rework QXmppLogger yet again
Diffstat (limited to 'source')
-rw-r--r--source/QXmppClient.cpp3
-rw-r--r--source/QXmppLogger.cpp68
-rw-r--r--source/QXmppLogger.h17
-rw-r--r--source/QXmppReconnectionManager.cpp2
-rw-r--r--source/QXmppStream.cpp2
-rw-r--r--source/QXmppUtils.cpp10
-rw-r--r--source/QXmppUtils.h3
7 files changed, 44 insertions, 61 deletions
diff --git a/source/QXmppClient.cpp b/source/QXmppClient.cpp
index 76620139..4f2c0275 100644
--- a/source/QXmppClient.cpp
+++ b/source/QXmppClient.cpp
@@ -187,7 +187,7 @@ void QXmppClient::connectToServer(const QString& host,
else
{
qWarning("QXmppClient::connectToServer: Invalid bareJid");
- logger()->debug() << QString("Invalid bareJid");
+ logger()->debug("Invalid bareJid");
}
}
@@ -521,6 +521,7 @@ QXmppTransferManager& QXmppClient::getTransferManager()
bool QXmppClient::handleStreamElement(const QDomElement &element)
{
+ Q_UNUSED(element);
return false;
}
diff --git a/source/QXmppLogger.cpp b/source/QXmppLogger.cpp
index e614cb86..d943bceb 100644
--- a/source/QXmppLogger.cpp
+++ b/source/QXmppLogger.cpp
@@ -21,58 +21,28 @@
*
*/
-#include <QDebug>
-#include <QFile>
-#include <QTime>
#include "QXmppLogger.h"
+#include <iostream>
+#include <QTime>
QXmppLogger* QXmppLogger::m_logger = 0;
QXmppLogger::QXmppLogger()
- : m_loggingType(QXmppLogger::NONE), m_device(0)
-{
-}
-
-QXmppLogger::~QXmppLogger()
+ : m_file("QXmppClientLog.log"), m_loggingType(QXmppLogger::FILE)
{
- delete m_device;
}
QXmppLogger* QXmppLogger::getLogger()
{
if(!m_logger)
- {
m_logger = new QXmppLogger();
- m_logger->setLoggingType(QXmppLogger::FILE);
- }
return m_logger;
}
void QXmppLogger::setLoggingType(QXmppLogger::LoggingType log)
{
- if (m_device)
- {
- delete m_device;
- m_device = 0;
- }
-
- QFile *file = 0;
- switch(log)
- {
- case QXmppLogger::FILE:
- file = new QFile("QXmppClientLog.log");
- file->open(QIODevice::Append);
- break;
- case QXmppLogger::STDOUT:
- file = new QFile();
- file->open(stdout, QIODevice::WriteOnly);
- break;
- case QXmppLogger::NONE:
- break;
- }
- m_device = file;
m_loggingType = log;
}
@@ -81,11 +51,35 @@ QXmppLogger::LoggingType QXmppLogger::loggingType()
return m_loggingType;
}
-QDebug QXmppLogger::debug()
+void QXmppLogger::debug(const QString &str)
+{
+ log(QtDebugMsg, str);
+}
+
+void QXmppLogger::warning(const QString &str)
{
- if (m_device)
- return QDebug(m_device) << QTime::currentTime().toString("hh:mm:ss.zzz") << ":";
- return QDebug(m_device);
+ log(QtWarningMsg, str);
+}
+
+void QXmppLogger::log(QtMsgType type, const QString& str)
+{
+ switch(m_loggingType)
+ {
+ case QXmppLogger::FILE:
+ m_file.open(QIODevice::Append);
+ m_stream.setDevice(&m_file);
+ m_stream << QTime::currentTime().toString("hh:mm:ss.zzz") << " : "<<
+ str << "\n\n";
+ m_file.close();
+ break;
+ case QXmppLogger::STDOUT:
+ std::cout<<qPrintable(str)<<std::endl;
+ break;
+ case QXmppLogger::NONE:
+ break;
+ default:
+ break;
+ }
}
QXmppLogger::LoggingType QXmppLogger::getLoggingType()
diff --git a/source/QXmppLogger.h b/source/QXmppLogger.h
index 271dd389..56ee35a6 100644
--- a/source/QXmppLogger.h
+++ b/source/QXmppLogger.h
@@ -26,8 +26,7 @@
#define QXMPPLOGGER_H
#include <QTextStream>
-
-class QIODevice;
+#include <QFile>
/// Singleton class
class QXmppLogger
@@ -41,22 +40,24 @@ public:
};
static QXmppLogger* getLogger();
-
QXmppLogger::LoggingType loggingType();
void setLoggingType(QXmppLogger::LoggingType);
- QDebug debug();
+ void debug(const QString& str);
+ void warning(const QString &str);
- // deprecated methods
+ // deprecated accessors, use the form without "get" instead
QXmppLogger::LoggingType Q_DECL_DEPRECATED getLoggingType();
-private:
+protected:
QXmppLogger();
- ~QXmppLogger();
+ virtual void log(QtMsgType type, const QString& str);
+private:
static QXmppLogger* m_logger;
QXmppLogger::LoggingType m_loggingType;
- QIODevice *m_device;
+ QFile m_file;
+ QTextStream m_stream;
};
#endif // QXMPPLOGGER_H
diff --git a/source/QXmppReconnectionManager.cpp b/source/QXmppReconnectionManager.cpp
index 006b12b9..20ddbb69 100644
--- a/source/QXmppReconnectionManager.cpp
+++ b/source/QXmppReconnectionManager.cpp
@@ -83,7 +83,7 @@ void QXmppReconnectionManager::reconnect()
{
if(m_client)
{
- m_client->logger()->debug() << QString("QXmppReconnectionManager::reconnect()");
+ m_client->logger()->debug("QXmppReconnectionManager::reconnect()");
emit reconnectingNow();
m_client->connectToServer(m_client->getConfiguration());
}
diff --git a/source/QXmppStream.cpp b/source/QXmppStream.cpp
index 7f479574..e61d881b 100644
--- a/source/QXmppStream.cpp
+++ b/source/QXmppStream.cpp
@@ -242,7 +242,7 @@ void QXmppStream::sendNonSASLAuthQuery( const QString &to )
void QXmppStream::log(const QString &data)
{
- m_client->logger()->debug() << data;
+ m_client->logger()->debug(data);
}
void QXmppStream::parser(const QByteArray& data)
diff --git a/source/QXmppUtils.cpp b/source/QXmppUtils.cpp
index 430b34d0..f59462a1 100644
--- a/source/QXmppUtils.cpp
+++ b/source/QXmppUtils.cpp
@@ -117,16 +117,6 @@ void helperToXmlAddTextElement(QXmlStreamWriter* stream, const QString& name,
stream->writeEmptyElement(name);
}
-void log(const QString& str)
-{
- QXmppLogger::getLogger()->debug() << str;
-}
-
-void log(const QByteArray& str)
-{
- QXmppLogger::getLogger()->debug() << str;
-}
-
QString escapeString(const QString& str)
{
QString strOut = str;
diff --git a/source/QXmppUtils.h b/source/QXmppUtils.h
index 7251bde2..8479a29b 100644
--- a/source/QXmppUtils.h
+++ b/source/QXmppUtils.h
@@ -52,9 +52,6 @@ void helperToXmlAddTextElement(QXmlStreamWriter* stream, const QString& name,
void helperToXmlAddNumberElement(QXmlStreamWriter* stream, const QString& name,
int value);
-void Q_DECL_DEPRECATED log(const QString& str);
-void Q_DECL_DEPRECATED log(const QByteArray& str);
-
QString escapeString(const QString& str);
QString unescapeString(const QString& str);