Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxLogFile.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #ifndef CXLOGFILE_H
34 #define CXLOGFILE_H
35 
36 #include "cxResourceExport.h"
37 #include "cxLogMessage.h"
38 
39 namespace cx
40 {
41 
46 class LogFile
47 {
48 public:
49  explicit LogFile();
50  static LogFile fromChannel(QString path, QString channel);
51  static LogFile fromFilename(QString filename);
52  virtual ~LogFile() {}
53 
54  void writeHeader();
55  void write(Message message);
56  bool isWritable() const;
57  QString getFilename() const;
58 
59  std::vector<Message> readMessages();
60 
61 private:
62  QString mPath;
63  QString mChannel;
64  int mFilePosition;
65  QDateTime mInitTimestamp;
66 
67  Message readMessageFirstLine(QString line);
68  MESSAGE_LEVEL readMessageLevel(QString line);
69  QRegExp getRX_Timestamp() const;
70  QString formatMessage(Message msg);
71  bool appendToLogfile(QString filename, QString text);
72  QString readFileTail();
73 // QString removeEarlierSessionsAndSetStartTime(QString text);
74 // std::vector<std::pair<QDateTime, QString> > splitIntoSessions(QString text);
75  QString timestampFormat() const;
76  QDateTime readTimestampFromSessionStartLine(QString text);
77 
78  void parseTimestamp(QString text, Message* retval);
79  void parseThread(QString text, Message* retval);
80  void parseSourceFileLine(QString text, Message* retval);
81  void parseSourceFunction(QString text, Message* retval);
82  QString getIndex(const QStringList& list, int index);
83 
84 };
85 
86 } //namespace cx
87 
88 
89 #endif // CXLOGFILE_H
std::vector< Message > readMessages()
Definition: cxLogFile.cpp:158
void write(Message message)
Definition: cxLogFile.cpp:82
void writeHeader()
Definition: cxLogFile.cpp:73
static LogFile fromFilename(QString filename)
Definition: cxLogFile.cpp:65
static LogFile fromChannel(QString path, QString channel)
Definition: cxLogFile.cpp:52
QString getFilename() const
Definition: cxLogFile.cpp:60
virtual ~LogFile()
Definition: cxLogFile.h:52
bool isWritable() const
Definition: cxLogFile.cpp:88