CustusX  16.5
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  MessageFilterConsole() : mChannel("") {}
86  virtual bool operator()(const Message& msg) const
87  {
88  if (!isActiveChannel(msg))
89  return false;
90  if (!isActiveSeverity(msg))
91  return false;
92  return true;
93  }
94 
96  {
97  return MessageFilterPtr(new MessageFilterConsole(*this));
98  }
99 
100 
101  bool isActiveSeverity(const Message& msg) const
102  {
103  LOG_SEVERITY severity = level2severity(msg.getMessageLevel());
104  return severity <= mLowestSeverity;
105  }
106 
107  bool isActiveChannel(const Message& msg) const
108  {
109  if (mChannel == "all")
110  return true;
111  if (msg.mChannel == mChannel)
112  return true;
113  return false;
114  }
115 
116  void setActiveChannel(QString uid)
117  {
118  mChannel = uid;
119  }
120 
122  {
123  mLowestSeverity = msERROR;
124  }
125  void activateSeverity(LOG_SEVERITY severity)
126  {
127  mLowestSeverity = std::max(mLowestSeverity, severity);
128  }
129  void setLowestSeverity(LOG_SEVERITY severity)
130  {
131  mLowestSeverity = severity;
132  }
133  LOG_SEVERITY getLowestSeverity() const
134  {
135  return mLowestSeverity;
136  }
137 
138 private:
139  QString mChannel;
140  LOG_SEVERITY mLowestSeverity;
141 };
142 
143 
144 } // namespace cx
145 
146 #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