MeVisLab Toolbox Reference
mlLogging.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2009, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef ML_LOGGING_H
14#define ML_LOGGING_H
15
16#include "mlUtilsSystem.h"
17#include "mlTypeDefs.h"
18
19#include <ThirdPartyWarningsDisable.h>
20#include <sstream>
21#include <ThirdPartyWarningsRestore.h>
22
24
25//--------------------------------------------------------------------------------------------
26//
43//--------------------------------------------------------------------------------------------
44
47#define mlFatalError(FUNCTION, ...) \
48 ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_FATAL, ML_NAMESPACE::internal::LogCollector::getErrorCode(__VA_ARGS__) ,FUNCTION).getStream()
49
52#define mlError(FUNCTION, ...) \
53 ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_ERROR, ML_NAMESPACE::internal::LogCollector::getErrorCode(__VA_ARGS__) , FUNCTION).getStream()
54
57#define mlWarning(FUNCTION, ...) \
58 ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_WARNING, ML_NAMESPACE::internal::LogCollector::getErrorCode(__VA_ARGS__) , FUNCTION).getStream()
59
62#define mlInfo(FUNCTION) \
63 ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_INFORMATION, ML_RESULT_OK, FUNCTION).getStream()
64
65
67#define mlFatalErrorWithDump(FUNCTION, ERRORCODE, OBJECT) \
68 ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_FATAL, ERRORCODE, FUNCTION, (OBJECT), ML_NAMESPACE::internal::MLSecureGetRuntimeTypeId((OBJECT))).getStream()
69
71#define mlErrorWithDump(FUNCTION, ERRORCODE, OBJECT) \
72 ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_ERROR, ERRORCODE, FUNCTION, (OBJECT), ML_NAMESPACE::internal::MLSecureGetRuntimeTypeId((OBJECT))).getStream()
73
75#define mlWarningWithDump(FUNCTION, ERRORCODE, OBJECT) \
76 ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_WARNING, ERRORCODE, FUNCTION, (OBJECT), ML_NAMESPACE::internal::MLSecureGetRuntimeTypeId((OBJECT))).getStream()
77
79#define mlInfoWithDump(FUNCTION, OBJECT) \
80 ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_INFORMATION, ML_RESULT_OK, FUNCTION, (OBJECT), ML_NAMESPACE::internal::MLSecureGetRuntimeTypeId((OBJECT))).getStream()
81
83
84#ifndef DOXYGEN_SHOULD_SKIP_THIS
85
86class RuntimeType;
87
88namespace internal {
89
90template <typename T>
91inline const RuntimeType* MLSecureGetRuntimeTypeId(const T* object) {
92 const RuntimeType* type = nullptr;
93 if (object) {
94 try {
95 type = object->getTypeId();
96 } catch(...) {};
97 }
98 return type;
99}
100
101#ifdef _MSC_VER
102#pragma warning( push )
103// suppress warning that doesn't seem to be relevant:
104#pragma warning(disable : 4251 ) // class 'std::ostringstream' needs to have dll-interface to be used by clients of class 'ml::OpenGL'
105#endif
106
109{
110public:
112 LogCollector(const char* file, int line, MLMessageType type, MLErrorCode errorCode,
113 const char *functionName,
114 const void *dumpObj = nullptr,
115 const RuntimeType *dumpObjRT= nullptr);
116
119
121 std::ostringstream& getStream() { return _stream; }
122
124 static int getErrorCode(int code) { return code; }
125 static int getErrorCode() { return ML_BAD_PARAMETER; }
126
127private:
128 std::ostringstream _stream;
129 const char* _file;
130 int _line;
131 MLMessageType _type;
132 MLErrorCode _errorCode;
133 const char* _functionName;
134 const void *_dumpObj;
135 const RuntimeType *_dumpObjRT;
136};
137
138#ifdef _MSC_VER
139#pragma warning( pop )
140#endif
141
142} // end namespace internal
143
144#endif // DOXYGEN_SHOULD_SKIP_THIS
145
147
148
149#endif // __mlLogging_H
150
@ T
#define ML_BAD_PARAMETER
A bad/invalid parameter (or even an inappropriate image) has been passed to a module or an algorithm;...
Definition mlTypeDefs.h:823
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:716
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
MLMessageType
Message types handled by the ErrorOutput class.
Definition mlTypeDefs.h:696
#define ML_UTILS_EXPORT
Defines platform dependent DLL export macro for mlUtils.
Definition mlUtilities.h:20