GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_tracelog.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 
23 #include "glc_tracelog.h"
24 
25 #include <QDir>
26 #include "glc_global.h"
27 #include <QMutexLocker>
28 
31 bool GLC_TraceLog::m_IsEnable= false;
32 
33 GLC_TraceLog::GLC_TraceLog(const QString& fullLogFileName)
34 : GLC_Log(fullLogFileName)
35 {
36 
37 }
38 
40 {
41 
42 }
43 
45 {
46  if (NULL == m_pTraceLog)
47  {
48  if (baseName.isEmpty())
49  {
50  QString fileName(QApplication::applicationName());
51  if (fileName.isEmpty())
52  {
53  baseName= "GLC_lib_TraceLog";
54  }
55  else
56  {
57  baseName= fileName + "_TraceLog";
58  }
59  }
60  QString logFileName(QDir::tempPath() + QDir::separator() + baseName);
61  m_pTraceLog= new GLC_TraceLog(logFileName);
63  }
64  return m_pTraceLog;
65 }
66 
68 {
69  return (NULL == m_pTraceLog);
70 }
71 
73 {
74  return m_IsEnable;
75 }
76 
77 void GLC_TraceLog::addTrace(const QStringList& traceDescription)
78 {
79  if (m_IsEnable)
80  {
81  QMutexLocker locker(&m_Mutex);
84  const int size= traceDescription.size();
85  for (int i= 0; i < size; ++i)
86  {
87  GLC_TraceLog::instance()->add(traceDescription.at(i));
88  }
89  }
90 }
92 {
93  QMutexLocker locker(&m_Mutex);
94  delete m_pTraceLog;
95  m_pTraceLog= NULL;
96 }
97 
98 void GLC_TraceLog::setEnabled(bool enable)
99 {
100  m_IsEnable= enable;
101 }
102 
104 {
105  QString currentLine;
106  currentLine= "Trace Log file";
107  GLC_Log::m_TextStream << currentLine << '\n';
108  currentLine= "Application " + QCoreApplication::applicationName();
109  GLC_Log::m_TextStream << currentLine << '\n';
110  currentLine= QDate::currentDate().toString(Qt::ISODate);
111  GLC_Log::m_TextStream << currentLine << '\n';
112  GLC_Log::m_TextStream.flush();
113 }

©2005-2013 Laurent Ribon