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