From 4bb18146d12ad2af36ec4e609a010f86be05730a Mon Sep 17 00:00:00 2001 From: Manjeet Dahiya Date: Sun, 14 Jun 2009 10:58:36 +0000 Subject: add --- source/QXmppLogger.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 source/QXmppLogger.cpp (limited to 'source/QXmppLogger.cpp') diff --git a/source/QXmppLogger.cpp b/source/QXmppLogger.cpp new file mode 100644 index 00000000..30b57eb9 --- /dev/null +++ b/source/QXmppLogger.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2008-2009 Manjeet Dahiya + * + * Author: + * Manjeet Dahiya + * + * Source: + * http://code.google.com/p/qxmpp + * + * This file is a part of QXmpp library. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + */ + + +#include "QXmppLogger.h" +#include +#include + +QXmppLogger* QXmppLogger::m_logger = 0; +QXmppLogger::LoggingType QXmppLogger::m_loggingType = QXmppLogger::FILE; +QFile QXmppLogger::m_file("QXmppClientLog.log"); +QTextStream QXmppLogger::m_stream; + +QXmppLogger::QXmppLogger() +{ +} + +QXmppLogger* QXmppLogger::getLogger() +{ + if(!m_logger) + m_logger = new QXmppLogger(); + + return m_logger; +} + +void QXmppLogger::setLoggingType(QXmppLogger::LoggingType log) +{ + m_loggingType = log; +} + +QXmppLogger::LoggingType QXmppLogger::getLoggingType() +{ + return m_loggingType; +} + +void QXmppLogger::log(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<