GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_log.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_log.h"
26 #include <QtDebug>
27 #include <QTime>
28 
29 GLC_Log::GLC_Log(const QString& baseLogFileName)
30 : m_pFile(new QTemporaryFile(baseLogFileName))
31 , m_TextStream()
32 {
33  Q_CHECK_PTR(m_pFile);
34  m_pFile->open();
35  m_pFile->setAutoRemove(false);
36  m_TextStream.setDevice(m_pFile);
37 }
38 
40 {
41  m_TextStream.flush();
42  delete m_pFile;
43 }
44 
45 QString GLC_Log::fullFileName() const
46 {
47  Q_ASSERT(NULL != m_pFile);
48  return m_pFile->fileName();
49 }
50 
51 void GLC_Log::add(const QString& line)
52 {
53  Q_ASSERT(NULL != m_pFile);
54  qWarning() << line;
55  m_TextStream << line << '\n';
56  m_TextStream.flush();
57 }
58 
60 {
61  Q_ASSERT(NULL != m_pFile);
62  const QString separator("---------------------------------------------------------------------");
63  qWarning() << separator;
64  m_TextStream << separator << '\n';
65  m_TextStream.flush();
66 }
67 
69 {
70  Q_ASSERT(NULL != m_pFile);
71  m_TextStream << QTime::currentTime().toString() << '\n';
72  m_TextStream.flush();
73 }

©2005-2013 Laurent Ribon