Main Page | Class List | File List | Class Members | File Members | Related Pages

logger.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Bojan D.                                        *
00003  *   bojan_d@users.sourceforge.net                                         *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00027 #include <kglobal.h>
00028 #include <klocale.h>
00029 #include <kdebug.h>
00030 #include <qdatetime.h>
00031 
00032 #include "logger.h"
00033 
00034 Logger::Logger(QObject *parent, const char *name)
00035         : QObject(parent, name),
00036         m_file(Config().Log.Path),
00037         m_log()
00038 {
00039         openFile();
00040 }
00041 
00042 
00043 Logger::~Logger()
00044 {
00045         m_log.unsetDevice();
00046         // destructor would have done it anyways...
00047         m_file.close();
00048 }
00049 
00050 void Logger::print(const QString& text, int type)
00051 {
00052         if(type == Configuration::Normal)
00053         {
00054                 if(Config().Log.UseLog)
00055                 {
00056                         m_log << KGlobal::locale()->formatDateTime(QDateTime::currentDateTime()) << ": " << text << endl << flush;
00057                 }
00058         }
00059         else if(type == Configuration::Debug)
00060         {
00061                 kdDebug() << KGlobal::locale()->formatDateTime(QDateTime::currentDateTime()) << ": " << text << endl << flush;  
00062         }
00063 }
00064 
00065 void Logger::printDebug(const QString& text)
00066 {
00067         print(text, Configuration::Debug);
00068 }
00069 
00070 void Logger::reload()
00071 {
00072         m_log.unsetDevice();
00073         m_file.close();
00074         openFile();
00075 }
00076 
00077 void Logger::openFile()
00078 {
00079         if(!m_file.open(IO_WriteOnly ))
00080         {
00081                 print(i18n("Can't open file '%1' for writing.").arg(Config().Log.Path), Configuration::Debug);
00082                 Config().Log.UseLog = false;
00083         }
00084         else
00085         {
00086                 m_log.setDevice(&m_file);
00087                 print("Opened log file.");
00088         }
00089 }       
00090 
00091 #include "logger.moc"

Generated on Mon Sep 5 12:52:34 2005 for kwebsnap.kdevelop by  doxygen 1.3.9.1