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_errorlog.h" 00026 #include <QDir> 00027 #include "glc_global.h" 00028 #include <QMutexLocker> 00029 00030 GLC_ErrorLog* GLC_ErrorLog::m_pErrorLog= NULL; 00031 QMutex GLC_ErrorLog::m_Mutex; 00032 00033 GLC_ErrorLog::GLC_ErrorLog(const QString& fullLogFileName) 00034 : GLC_Log(fullLogFileName) 00035 { 00036 00037 } 00038 00039 GLC_ErrorLog::~GLC_ErrorLog() 00040 { 00041 00042 } 00043 00044 GLC_ErrorLog* GLC_ErrorLog::instance() 00045 { 00046 if (NULL == m_pErrorLog) 00047 { 00048 QString fileName(QApplication::applicationName()); 00049 if (fileName.isEmpty()) 00050 { 00051 fileName= "GLC_lib_ErrLog"; 00052 } 00053 else 00054 { 00055 fileName= fileName + "_ErrLog"; 00056 } 00057 QString logFileName(QDir::tempPath() + QDir::separator() + fileName); 00058 m_pErrorLog= new GLC_ErrorLog(logFileName); 00059 m_pErrorLog->writeHeader(); 00060 } 00061 return m_pErrorLog; 00062 } 00063 00064 bool GLC_ErrorLog::isEmpty() 00065 { 00066 return (NULL == m_pErrorLog); 00067 } 00068 00069 void GLC_ErrorLog::addError(const QStringList& errorDescription) 00070 { 00071 QMutexLocker locker(&m_Mutex); 00072 GLC_ErrorLog::instance()->addSeparator(); 00073 GLC_ErrorLog::instance()->addCurrentTime(); 00074 const int size= errorDescription.size(); 00075 for (int i= 0; i < size; ++i) 00076 { 00077 GLC_ErrorLog::instance()->add(errorDescription.at(i)); 00078 } 00079 } 00080 void GLC_ErrorLog::close() 00081 { 00082 QMutexLocker locker(&m_Mutex); 00083 delete m_pErrorLog; 00084 m_pErrorLog= NULL; 00085 } 00086 00087 void GLC_ErrorLog::writeHeader() 00088 { 00089 QString currentLine; 00090 currentLine= "Error Log file"; 00091 GLC_Log::m_TextStream << currentLine << '\n'; 00092 currentLine= "Application " + QCoreApplication::applicationName(); 00093 GLC_Log::m_TextStream << currentLine << '\n'; 00094 currentLine= QDate::currentDate().toString(Qt::ISODate); 00095 GLC_Log::m_TextStream << currentLine << '\n'; 00096 GLC_Log::m_TextStream.flush(); 00097 }