MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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//
44//--------------------------------------------------------------------------------------------
45
48#define mlFatalError(FUNCTION, ...) \
49 ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_FATAL, \
50 ML_NAMESPACE::internal::LogCollector::getErrorCode(__VA_ARGS__), FUNCTION) \
51 .getStream()
52
55#define mlError(FUNCTION, ...) \
56 ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_ERROR, \
57 ML_NAMESPACE::internal::LogCollector::getErrorCode(__VA_ARGS__), FUNCTION) \
58 .getStream()
59
62#define mlWarning(FUNCTION, ...) \
63 ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_WARNING, \
64 ML_NAMESPACE::internal::LogCollector::getErrorCode(__VA_ARGS__), FUNCTION) \
65 .getStream()
66
69#define mlInfo(FUNCTION) \
70 ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_INFORMATION, ML_RESULT_OK, FUNCTION).getStream()
71
72
75#define mlFatalErrorWithDump(FUNCTION, ERRORCODE, OBJECT) \
76 ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_FATAL, ERRORCODE, FUNCTION, (OBJECT), \
77 ML_NAMESPACE::internal::MLSecureGetRuntimeTypeId((OBJECT))) \
78 .getStream()
79
82#define mlErrorWithDump(FUNCTION, ERRORCODE, OBJECT) \
83 ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_ERROR, ERRORCODE, FUNCTION, (OBJECT), \
84 ML_NAMESPACE::internal::MLSecureGetRuntimeTypeId((OBJECT))) \
85 .getStream()
86
89#define mlWarningWithDump(FUNCTION, ERRORCODE, OBJECT) \
90 ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_WARNING, ERRORCODE, FUNCTION, (OBJECT), \
91 ML_NAMESPACE::internal::MLSecureGetRuntimeTypeId((OBJECT))) \
92 .getStream()
93
96#define mlInfoWithDump(FUNCTION, OBJECT) \
97 ML_NAMESPACE::internal::LogCollector(__FILE__, __LINE__, ML_INFORMATION, ML_RESULT_OK, FUNCTION, (OBJECT), \
98 ML_NAMESPACE::internal::MLSecureGetRuntimeTypeId((OBJECT))) \
99 .getStream()
100
102
103#ifndef DOXYGEN_SHOULD_SKIP_THIS
104
105class RuntimeType;
106
107namespace internal
108{
109
110 template <typename T> inline const RuntimeType* MLSecureGetRuntimeTypeId(const T* object)
111 {
112 const RuntimeType* type = nullptr;
113 if (object) {
114 try {
115 type = object->getTypeId();
116 }
117 catch (...) {
118 };
119 }
120 return type;
121 }
122
123#ifdef _MSC_VER
124#pragma warning(push)
125// Suppresses warning that does not seem to be relevant:
126#pragma warning( \
127 disable \
128 : 4251) // class 'std::ostringstream' needs to have dll-interface to be used by clients of class 'ml::OpenGL'
129#endif
130
133 {
134 public:
136 LogCollector(const char* file, int line, MLMessageType type, MLErrorCode errorCode, const char* functionName,
137 const void* dumpObj = nullptr, const RuntimeType* dumpObjRT = nullptr);
138
141
143 std::ostringstream& getStream()
144 {
145 return _stream;
146 }
147
149 static int getErrorCode(int code)
150 {
151 return code;
152 }
153 static int getErrorCode()
154 {
155 return ML_BAD_PARAMETER;
156 }
157
158 private:
159 std::ostringstream _stream;
160 const char* _file;
161 int _line;
162 MLMessageType _type;
163 MLErrorCode _errorCode;
164 const char* _functionName;
165 const void* _dumpObj;
166 const RuntimeType* _dumpObjRT;
167 };
168
169#ifdef _MSC_VER
170#pragma warning(pop)
171#endif
172
173} // end namespace internal
174
175#endif // DOXYGEN_SHOULD_SKIP_THIS
176
178
179
180#endif // __mlLogging_H
@ 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:879
MLint32 MLErrorCode
Type of an ML Error code.
Definition mlTypeDefs.h:772
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
MLMessageType
Message types handled by the ErrorOutput class.
Definition mlTypeDefs.h:750
#define ML_UTILS_EXPORT
Definition mlUtilities.h:18