Fraxinus  17.12-rc2
An IGT application
cxLogger.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 
33 
34 #ifndef CXLOGGER_H_
35 #define CXLOGGER_H_
36 
37 #include "cxResourceExport.h"
38 #include "cxDefinitions.h"
39 #include "cxTypeConversions.h"
40 #include "boost/shared_ptr.hpp"
41 
52 namespace cx
53 {
54 
59 class cxResource_EXPORT MessageLogger
60 {
61 public:
62  MessageLogger(const char *file, int line, const char *function, const QString& channel, MESSAGE_LEVEL severity);
63  ~MessageLogger();
64 
65  MessageLogger logger() const;
66  MessageLogger logger(QString text) const;
67 
68  template <class T>
70  {
71  this->getStream() << value;
72  return *this;
73  }
74 
75 private:
76  boost::shared_ptr<class MessageLoggerInternalData> mInternalData;
77  std::stringstream& getStream();
78 };
79 
80 //template <class T>
81 //cxResource_EXPORT MessageLogger& operator<<(MessageLogger& logger, const T& value)
82 //{
83 // logger << value;
84 // return logger;
85 //}
86 
87 cxResource_EXPORT void reportDebug(QString msg);
88 cxResource_EXPORT void report(QString msg);
89 cxResource_EXPORT void reportWarning(QString msg);
90 cxResource_EXPORT void reportError(QString msg);
91 cxResource_EXPORT void reportSuccess(QString msg);
92 cxResource_EXPORT void reportVolatile(QString msg);
93 
94 } //namespace cx
95 
96 
97 #define CX_LOG_SEVERITY_INTERNAL(severity) \
98  cx::MessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, "console", severity)
99 
100 #define CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, severity) \
101  cx::MessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, channel, severity)
102 
103 
109 #define CX_LOG_DEBUG_CHECKPOINT() CX_LOG_CHANNEL_SEVERITY_INTERNAL("checkpoints", cx::mlDEBUG).logger() << "CHECKPOINT: " << __FILE__ << " at " << __LINE__ << " in " << Q_FUNC_INFO << " : "
110 
116 #define CX_LOG_DEBUG CX_LOG_SEVERITY_INTERNAL(cx::mlDEBUG).logger
117 #define CX_LOG_INFO CX_LOG_SEVERITY_INTERNAL(cx::mlINFO).logger
118 #define CX_LOG_SUCCESS CX_LOG_SEVERITY_INTERNAL(cx::mlSUCCESS).logger
119 #define CX_LOG_WARNING CX_LOG_SEVERITY_INTERNAL(cx::mlWARNING).logger
120 #define CX_LOG_ERROR CX_LOG_SEVERITY_INTERNAL(cx::mlERROR).logger
121 #define CX_LOG_VOLATILE CX_LOG_SEVERITY_INTERNAL(cx::mlVOLATILE).logger
122 
128 #define CX_LOG_CHANNEL_DEBUG(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlDEBUG).logger()
129 #define CX_LOG_CHANNEL_INFO(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlINFO).logger()
130 #define CX_LOG_CHANNEL_SUCCESS(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlSUCCESS).logger()
131 #define CX_LOG_CHANNEL_WARNING(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlWARNING).logger()
132 #define CX_LOG_CHANNEL_ERROR(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlERROR).logger()
133 #define CX_LOG_CHANNEL_VOLATILE(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlVOLATILE).logger()
134 
137 #define CX_ASSERT(statement) \
138 { \
139  if (!(statement)) \
140  { \
141  CX_LOG_ERROR("Assert failure!");\
142  } \
143 }
144 
149 #endif
void reportError(QString msg)
Definition: cxLogger.cpp:92
void reportVolatile(QString msg)
Definition: cxLogger.cpp:94
void reportWarning(QString msg)
Definition: cxLogger.cpp:91
MessageLogger & operator<<(T value)
Definition: cxLogger.h:69
void reportSuccess(QString msg)
Definition: cxLogger.cpp:93
void report(QString msg)
Definition: cxLogger.cpp:90
void reportDebug(QString msg)
Definition: cxLogger.cpp:89
Namespace for all CustusX production code.