CustusX  2023.01.05-dev+develop.0da12
An IGT application
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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #ifndef CXLOGFILE_H
13 #define CXLOGFILE_H
14 
15 #include "cxResourceExport.h"
16 #include "cxLogMessage.h"
17 
18 namespace cx
19 {
20 
25 class LogFile
26 {
27 public:
28  explicit LogFile();
29  static LogFile fromChannel(QString path, QString channel);
30  static LogFile fromFilename(QString filename);
31  virtual ~LogFile() {}
32 
33  void writeHeader();
34  void write(Message message);
35  bool isWritable() const;
36  QString getFilename() const;
37 
38  std::vector<Message> readMessages();
39 
40 private:
41  QString mPath;
42  QString mChannel;
43  int mFilePosition;
44  QDateTime mInitTimestamp;
45 
46  Message readMessageFirstLine(QString line);
47  MESSAGE_LEVEL readMessageLevel(QString line);
48  QRegExp getRX_Timestamp() const;
49  QString formatMessage(Message msg);
50  bool appendToLogfile(QString filename, QString text);
51  QString readFileTail();
52 // QString removeEarlierSessionsAndSetStartTime(QString text);
53 // std::vector<std::pair<QDateTime, QString> > splitIntoSessions(QString text);
54  QString timestampFormat() const;
55  QDateTime readTimestampFromSessionStartLine(QString text);
56 
57  void parseTimestamp(QString text, Message* retval);
58  void parseThread(QString text, Message* retval);
59  void parseSourceFileLine(QString text, Message* retval);
60  void parseSourceFunction(QString text, Message* retval);
61  QString getIndex(const QStringList& list, int index);
62 
63 };
64 
65 } //namespace cx
66 
67 
68 #endif // CXLOGFILE_H
std::vector< Message > readMessages()
Definition: cxLogFile.cpp:136
void write(Message message)
Definition: cxLogFile.cpp:60
void writeHeader()
Definition: cxLogFile.cpp:51
static LogFile fromFilename(QString filename)
Definition: cxLogFile.cpp:43
static LogFile fromChannel(QString path, QString channel)
Definition: cxLogFile.cpp:30
QString getFilename() const
Definition: cxLogFile.cpp:38
virtual ~LogFile()
Definition: cxLogFile.h:31
bool isWritable() const
Definition: cxLogFile.cpp:66
Namespace for all CustusX production code.