GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_errorlog.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  *****************************************************************************/
22 
24 
25 #include "glc_errorlog.h"
26 #include <QDir>
27 #include "glc_global.h"
28 #include <QMutexLocker>
29 
32 
33 GLC_ErrorLog::GLC_ErrorLog(const QString& fullLogFileName)
34 : GLC_Log(fullLogFileName)
35 {
36 
37 }
38 
40 {
41 
42 }
43 
45 {
46  if (NULL == m_pErrorLog)
47  {
48  QString fileName(QApplication::applicationName());
49  if (fileName.isEmpty())
50  {
51  fileName= "GLC_lib_ErrLog";
52  }
53  else
54  {
55  fileName= fileName + "_ErrLog";
56  }
57  QString logFileName(QDir::tempPath() + QDir::separator() + fileName);
58  m_pErrorLog= new GLC_ErrorLog(logFileName);
60  }
61  return m_pErrorLog;
62 }
63 
65 {
66  return (NULL == m_pErrorLog);
67 }
68 
69 void GLC_ErrorLog::addError(const QStringList& errorDescription)
70 {
71  QMutexLocker locker(&m_Mutex);
74  const int size= errorDescription.size();
75  for (int i= 0; i < size; ++i)
76  {
77  GLC_ErrorLog::instance()->add(errorDescription.at(i));
78  }
79 }
80 
81 void GLC_ErrorLog::addError(const QString &errorDescription)
82 {
83  QMutexLocker locker(&m_Mutex);
86 
87  GLC_ErrorLog::instance()->add(errorDescription);
88 }
89 
91 {
92  QMutexLocker locker(&m_Mutex);
93  delete m_pErrorLog;
94  m_pErrorLog= NULL;
95 }
96 
98 {
99  QString currentLine;
100  currentLine= "Error Log file";
101  GLC_Log::m_TextStream << currentLine << '\n';
102  currentLine= "Application " + QCoreApplication::applicationName();
103  GLC_Log::m_TextStream << currentLine << '\n';
104  currentLine= QDate::currentDate().toString(Qt::ISODate);
105  GLC_Log::m_TextStream << currentLine << '\n';
106  GLC_Log::m_TextStream.flush();
107 }

©2005-2013 Laurent Ribon