glc_log.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021  *****************************************************************************/
00022 
00024 
00025 #include "glc_log.h"
00026 #include <QtDebug>
00027 #include <QTime>
00028 
00029 GLC_Log::GLC_Log(const QString& baseLogFileName)
00030 : m_pFile(new QTemporaryFile(baseLogFileName))
00031 , m_TextStream()
00032 {
00033         Q_CHECK_PTR(m_pFile);
00034         m_pFile->open();
00035         m_pFile->setAutoRemove(false);
00036         m_TextStream.setDevice(m_pFile);
00037 }
00038 
00039 GLC_Log::~GLC_Log()
00040 {
00041         m_TextStream.flush();
00042         delete m_pFile;
00043 }
00044 
00045 QString GLC_Log::fullFileName() const
00046 {
00047         Q_ASSERT(NULL != m_pFile);
00048         return m_pFile->fileName();
00049 }
00050 
00051 void GLC_Log::add(const QString& line)
00052 {
00053         Q_ASSERT(NULL != m_pFile);
00054         qWarning() << line;
00055         m_TextStream << line << '\n';
00056         m_TextStream.flush();
00057 }
00058 
00059 void GLC_Log::addSeparator()
00060 {
00061         Q_ASSERT(NULL != m_pFile);
00062         const QString separator("---------------------------------------------------------------------");
00063         qWarning() << separator;
00064         m_TextStream << separator << '\n';
00065         m_TextStream.flush();
00066 }
00067 
00068 void GLC_Log::addCurrentTime()
00069 {
00070         Q_ASSERT(NULL != m_pFile);
00071         m_TextStream << QTime::currentTime().toString() << '\n';
00072         m_TextStream.flush();
00073 }

SourceForge.net Logo

©2005-2011 Laurent Ribon