CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxLogMessageFilter.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 #ifndef CXLOGMESSAGEFILTER_H
12 #define CXLOGMESSAGEFILTER_H
13 
14 #include "cxResourceExport.h"
15 #include "cxReporter.h"
16 
17 #include <vector>
18 #include <QPointer>
19 
20 #include <iostream>
21 #include "cxTypeConversions.h"
22 
23 namespace cx
24 {
25 
26 static LOG_SEVERITY level2severity(MESSAGE_LEVEL level)
27 {
28  switch (level)
29  {
30  // level 1
31  case mlCERR :
32  case mlERROR : return msERROR;
33 
34  // level 2
35  case mlSUCCESS :
36  case mlWARNING : return msWARNING;
37 
38  // level 3
39  case mlINFO : return msINFO;
40 
41  // level 4
42  case mlCOUT :
43  case mlDEBUG : return msDEBUG;
44 
45  default: return msCOUNT;
46  }
47 }
48 
49 typedef boost::shared_ptr<class MessageFilter> MessageFilterPtr;
50 
52 {
53 public:
55  virtual bool operator()(const Message& msg) const = 0;
56  virtual MessageFilterPtr clone() = 0;
57 
58 };
59 
61 {
62 public:
63  MessageFilterConsole() : mChannel("") {}
64  virtual bool operator()(const Message& msg) const
65  {
66  if (!isActiveChannel(msg))
67  return false;
68  if (!isActiveSeverity(msg))
69  return false;
70  return true;
71  }
72 
73  virtual MessageFilterPtr clone()
74  {
75  return MessageFilterPtr(new MessageFilterConsole(*this));
76  }
77 
78 
79  bool isActiveSeverity(const Message& msg) const
80  {
81  LOG_SEVERITY severity = level2severity(msg.getMessageLevel());
82  return severity <= mLowestSeverity;
83  }
84 
85  bool isActiveChannel(const Message& msg) const
86  {
87  if (mChannel == "all")
88  return true;
89  if (msg.mChannel == mChannel)
90  return true;
91  return false;
92  }
93 
94  void setActiveChannel(QString uid)
95  {
96  mChannel = uid;
97  }
98 
100  {
101  mLowestSeverity = msERROR;
102  }
103  void activateSeverity(LOG_SEVERITY severity)
104  {
105  mLowestSeverity = std::max(mLowestSeverity, severity);
106  }
107  void setLowestSeverity(LOG_SEVERITY severity)
108  {
109  mLowestSeverity = severity;
110  }
111  LOG_SEVERITY getLowestSeverity() const
112  {
113  return mLowestSeverity;
114  }
115 
116 private:
117  QString mChannel;
118  LOG_SEVERITY mLowestSeverity;
119 };
120 
121 
122 } // namespace cx
123 
124 #endif // CXLOGMESSAGEFILTER_H
void setActiveChannel(QString uid)
mlSUCCESS
Definition: cxDefinitions.h:67
bool isActiveChannel(const Message &msg) const
msDEBUG
Definition: cxDefinitions.h:81
virtual MessageFilterPtr clone()
mlCERR
Definition: cxDefinitions.h:67
msINFO
Definition: cxDefinitions.h:81
mlDEBUG
Definition: cxDefinitions.h:67
boost::shared_ptr< class MessageFilter > MessageFilterPtr
virtual MessageFilterPtr clone()=0
void setLowestSeverity(LOG_SEVERITY severity)
QString mChannel
Definition: cxLogMessage.h:74
msERROR
Definition: cxDefinitions.h:81
LOG_SEVERITY getLowestSeverity() const
void activateSeverity(LOG_SEVERITY severity)
mlINFO
Definition: cxDefinitions.h:67
mlCOUT
Definition: cxDefinitions.h:67
msWARNING
Definition: cxDefinitions.h:81
bool isActiveSeverity(const Message &msg) const
mlWARNING
Definition: cxDefinitions.h:67
MESSAGE_LEVEL getMessageLevel() const
The category of the message.
mlERROR
Definition: cxDefinitions.h:67
virtual bool operator()(const Message &msg) const
virtual bool operator()(const Message &msg) const =0
Namespace for all CustusX production code.