NorMIT-nav  22.09
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) 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 
12 
13 #ifndef CXLOGGER_H_
14 #define CXLOGGER_H_
15 
16 #include "cxResourceExport.h"
17 #include "cxDefinitions.h"
18 #include "cxTypeConversions.h"
19 #include "boost/shared_ptr.hpp"
20 
31 namespace cx
32 {
33 
38 class cxResource_EXPORT MessageLogger
39 {
40 public:
41  MessageLogger(const char *file, int line, const char *function, const QString& channel, MESSAGE_LEVEL severity);
42  ~MessageLogger();
43 
44  MessageLogger logger() const;
45  MessageLogger logger(QString text) const;
46 
47  template <class T>
49  {
50  this->getStream() << value;
51  return *this;
52  }
53 
54 private:
55  boost::shared_ptr<class MessageLoggerInternalData> mInternalData;
56  std::stringstream& getStream();
57 };
58 
59 //template <class T>
60 //cxResource_EXPORT MessageLogger& operator<<(MessageLogger& logger, const T& value)
61 //{
62 // logger << value;
63 // return logger;
64 //}
65 
66 cxResource_EXPORT void reportDebug(QString msg);
67 cxResource_EXPORT void report(QString msg);
68 cxResource_EXPORT void reportWarning(QString msg);
69 cxResource_EXPORT void reportError(QString msg);
70 cxResource_EXPORT void reportSuccess(QString msg);
71 cxResource_EXPORT void reportVolatile(QString msg);
72 
73 } //namespace cx
74 
75 
76 #define CX_LOG_SEVERITY_INTERNAL(severity) \
77  cx::MessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, "console", severity)
78 
79 #define CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, severity) \
80  cx::MessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, channel, severity)
81 
82 
88 #define CX_LOG_DEBUG_CHECKPOINT() CX_LOG_CHANNEL_SEVERITY_INTERNAL("checkpoints", cx::mlDEBUG).logger() << "CHECKPOINT: " << __FILE__ << " at " << __LINE__ << " in " << Q_FUNC_INFO << " : "
89 
95 #define CX_LOG_DEBUG CX_LOG_SEVERITY_INTERNAL(cx::mlDEBUG).logger
96 #define CX_LOG_INFO CX_LOG_SEVERITY_INTERNAL(cx::mlINFO).logger
97 #define CX_LOG_SUCCESS CX_LOG_SEVERITY_INTERNAL(cx::mlSUCCESS).logger
98 #define CX_LOG_WARNING CX_LOG_SEVERITY_INTERNAL(cx::mlWARNING).logger
99 #define CX_LOG_ERROR CX_LOG_SEVERITY_INTERNAL(cx::mlERROR).logger
100 #define CX_LOG_VOLATILE CX_LOG_SEVERITY_INTERNAL(cx::mlVOLATILE).logger
101 
107 #define CX_LOG_CHANNEL_DEBUG(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlDEBUG).logger()
108 #define CX_LOG_CHANNEL_INFO(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlINFO).logger()
109 #define CX_LOG_CHANNEL_SUCCESS(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlSUCCESS).logger()
110 #define CX_LOG_CHANNEL_WARNING(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlWARNING).logger()
111 #define CX_LOG_CHANNEL_ERROR(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlERROR).logger()
112 #define CX_LOG_CHANNEL_VOLATILE(channel) CX_LOG_CHANNEL_SEVERITY_INTERNAL(channel, cx::mlVOLATILE).logger()
113 
116 #define CX_ASSERT(statement) \
117 { \
118  if (!(statement)) \
119  { \
120  CX_LOG_ERROR("Assert failure!");\
121  } \
122 }
123 
128 #endif
cx::reportSuccess
void reportSuccess(QString msg)
Definition: cxLogger.cpp:72
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::reportDebug
void reportDebug(QString msg)
Definition: cxLogger.cpp:68
cx::report
void report(QString msg)
Definition: cxLogger.cpp:69
cxDefinitions.h
cx::MessageLogger::operator<<
MessageLogger & operator<<(T value)
Definition: cxLogger.h:48
cxTypeConversions.h
cx::MessageLogger
Definition: cxLogger.h:38
cx::reportError
void reportError(QString msg)
Definition: cxLogger.cpp:71
cx::reportVolatile
void reportVolatile(QString msg)
Definition: cxLogger.cpp:73
cx::reportWarning
void reportWarning(QString msg)
Definition: cxLogger.cpp:70