CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 #ifndef CXLOGMESSAGEFILTER_H
33 #define CXLOGMESSAGEFILTER_H
34 
35 #include "cxResourceExport.h"
36 #include "cxReporter.h"
37 
38 #include <vector>
39 #include <QPointer>
40 
41 #include "cxEnumConverter.h"
42 #include <iostream>
43 #include "cxTypeConversions.h"
44 
45 namespace cx
46 {
47 
48 static LOG_SEVERITY level2severity(MESSAGE_LEVEL level)
49 {
50  switch (level)
51  {
52  // level 1
53  case mlCERR :
54  case mlERROR : return msERROR;
55 
56  // level 2
57  case mlSUCCESS :
58  case mlWARNING : return msWARNING;
59 
60  // level 3
61  case mlINFO : return msINFO;
62 
63  // level 4
64  case mlCOUT :
65  case mlDEBUG : return msDEBUG;
66 
67  default: return msCOUNT;
68  }
69 }
70 
71 typedef boost::shared_ptr<class MessageFilter> MessageFilterPtr;
72 
74 {
75 public:
77  virtual bool operator()(const Message& msg) const = 0;
78  virtual MessageFilterPtr clone() = 0;
79 
80 };
81 
83 {
84 public:
85  virtual bool operator()(const Message& msg) const
86  {
87  if (!isActiveChannel(msg))
88  return false;
89  if (!isActiveSeverity(msg))
90  return false;
91  return true;
92  }
93 
95  {
96  return MessageFilterPtr(new MessageFilterConsole(*this));
97  }
98 
99 
100  bool isActiveSeverity(const Message& msg) const
101  {
102  LOG_SEVERITY severity = level2severity(msg.getMessageLevel());
103  return severity <= mLowestSeverity;
104  }
105 
106  bool isActiveChannel(const Message& msg) const
107  {
108  if (mChannel == "all")
109  return true;
110  if (msg.mChannel == mChannel)
111  return true;
112  return false;
113  }
114 
115  void setActiveChannel(QString uid)
116  {
117  mChannel = uid;
118  }
119 
121  {
122  mLowestSeverity = msERROR;
123  }
124  void activateSeverity(LOG_SEVERITY severity)
125  {
126  mLowestSeverity = std::max(mLowestSeverity, severity);
127  }
128  void setLowestSeverity(LOG_SEVERITY severity)
129  {
130  mLowestSeverity = severity;
131  }
132  LOG_SEVERITY getLowestSeverity() const
133  {
134  return mLowestSeverity;
135  }
136 
137 private:
138  QString mChannel;
139  LOG_SEVERITY mLowestSeverity;
140 };
141 
142 
143 } // namespace cx
144 
145 #endif // CXLOGMESSAGEFILTER_H
void setActiveChannel(QString uid)
mlSUCCESS
Definition: cxDefinitions.h:82
bool isActiveChannel(const Message &msg) const
msDEBUG
Definition: cxDefinitions.h:96
virtual MessageFilterPtr clone()
mlCERR
Definition: cxDefinitions.h:82
msINFO
Definition: cxDefinitions.h:96
mlDEBUG
Definition: cxDefinitions.h:82
boost::shared_ptr< class MessageFilter > MessageFilterPtr
virtual MessageFilterPtr clone()=0
void setLowestSeverity(LOG_SEVERITY severity)
QString mChannel
Definition: cxLogMessage.h:95
msERROR
Definition: cxDefinitions.h:96
LOG_SEVERITY getLowestSeverity() const
void activateSeverity(LOG_SEVERITY severity)
mlINFO
Definition: cxDefinitions.h:82
mlCOUT
Definition: cxDefinitions.h:82
msWARNING
Definition: cxDefinitions.h:96
bool isActiveSeverity(const Message &msg) const
mlWARNING
Definition: cxDefinitions.h:82
MESSAGE_LEVEL getMessageLevel() const
The category of the message.
mlERROR
Definition: cxDefinitions.h:82
virtual bool operator()(const Message &msg) const
virtual bool operator()(const Message &msg) const =0