CustusX  16.5.0-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
104 
110 #define CX_LOG_DEBUG CX_LOG_SEVERITY_INTERNAL(cx::mlDEBUG).logger
111 #define CX_LOG_INFO CX_LOG_SEVERITY_INTERNAL(cx::mlINFO).logger
112 #define CX_LOG_SUCCESS CX_LOG_SEVERITY_INTERNAL(cx::mlSUCCESS).logger
113 #define CX_LOG_WARNING CX_LOG_SEVERITY_INTERNAL(cx::mlWARNING).logger
114 #define CX_LOG_ERROR CX_LOG_SEVERITY_INTERNAL(cx::mlERROR).logger
115 #define CX_LOG_VOLATILE CX_LOG_SEVERITY_INTERNAL(cx::mlVOLATILE).logger
116 
122 #define CX_LOG_CHANNEL_DEBUG(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlDEBUG).logger()
123 #define CX_LOG_CHANNEL_INFO(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlINFO).logger()
124 #define CX_LOG_CHANNEL_SUCCESS(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlSUCCESS).logger()
125 #define CX_LOG_CHANNEL_WARNING(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlWARNING).logger()
126 #define CX_LOG_CHANNEL_ERROR(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlERROR).logger()
127 #define CX_LOG_CHANNEL_VOLATILE(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlVOLATILE).logger()
128 
131 #define CX_ASSERT(statement) \
132 { \
133  if (!(statement)) \
134  { \
135  CX_LOG_ERROR("Assert failure!");\
136  } \
137 }
138 
143 #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