Computer Assisted Medical Intervention Tool Kit  version 5.2
Log.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2024 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, TIMC, 38000 Grenoble, France
6  *
7  * Visit http://camitk.imag.fr for more information
8  *
9  * This file is part of CamiTK.
10  *
11  * CamiTK is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * CamiTK is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License version 3 for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * $CAMITK_LICENCE_END$
24  ****************************************************************************/
25 
26 #ifndef LOG_H
27 #define LOG_H
28 
29 // -- Core stuff
30 #include "CamiTKAPI.h"
31 #include "InterfaceLogger.h"
32 
33 namespace camitk {
34 
35 class InterfaceLogger;
36 
200 public:
204  static void setLogger(InterfaceLogger* logger);
205 
207  static InterfaceLogger* getLogger();
208 
210  static QString getLevelAsString(InterfaceLogger::LogLevel level);
211 
213  static InterfaceLogger::LogLevel getLevelFromString(QString levelString);
214 
215 private:
216  static InterfaceLogger* applicationLogger;
217 };
218 
220 #define CAMITK_PRINT_POINTER(PTR) (QString(#PTR) + QString("->[0x%1]").arg((quintptr)PTR, QT_POINTER_SIZE * 2, 16, QChar('0')))
221 
223 #if !defined(CAMITK_DISABLE_LOG)
224 #define CAMITK_LOG(LEVEL,MSG,SENDER) camitk::Log::getLogger()->log(MSG, LEVEL, __FILE__, Q_FUNC_INFO, __LINE__, SENDER);
225 #define CAMITK_LOG_ALT(LEVEL,MSG) camitk::Log::getLogger()->log(MSG, LEVEL, __FILE__, __func__, __LINE__);
226 #else
227 #define CAMITK_LOG(LEVEL,MSG,SENDER)
228 #define CAMITK_LOG_ALT(LEVEL,MSG)
229 #endif
230 
233 #define CAMITK_TRACE(MSG) CAMITK_LOG(camitk::InterfaceLogger::TRACE, MSG, this)
234 #define CAMITK_TRACE_ALT(MSG) CAMITK_LOG_ALT(camitk::InterfaceLogger::TRACE, MSG)
235 
238 #define CAMITK_INFO(MSG) CAMITK_LOG(camitk::InterfaceLogger::INFO, MSG, this)
239 #define CAMITK_INFO_ALT(MSG) CAMITK_LOG_ALT(camitk::InterfaceLogger::INFO, MSG)
240 
243 #define CAMITK_WARNING(MSG) CAMITK_LOG(camitk::InterfaceLogger::WARNING, MSG, this)
244 #define CAMITK_WARNING_ALT(MSG) CAMITK_LOG_ALT(camitk::InterfaceLogger::WARNING, MSG)
245 
248 #ifdef ERROR
249 #define CAMITK_WINDOWS_SYSTEM_ERROR_SAFEGUARD ERROR
250 #undef ERROR
251 #endif
252 
253 #define CAMITK_ERROR(MSG) CAMITK_LOG(camitk::InterfaceLogger::ERROR, MSG, this)
254 #define CAMITK_ERROR_ALT(MSG) CAMITK_LOG_ALT(camitk::InterfaceLogger::ERROR, MSG)
255 
256 #ifdef CAMITK_WINDOWS_SYSTEM_ERROR_SAFEGUARD
257 #define ERROR CAMITK_WINDOWS_SYSTEM_ERROR_SAFEGUARD
258 #endif
259 
262 #define CAMITK_TRACE_IF(COND, MSG) \
263 { \
264  if (((COND))) { \
265  CAMITK_TRACE(MSG) \
266  } \
267 }
268 
269 #define CAMITK_TRACE_IF_ALT(COND, MSG) \
270 { \
271  if (((COND))) { \
272  CAMITK_TRACE_ALT(MSG) \
273  } \
274 }
275 
276 #define CAMITK_INFO_IF(COND, MSG) \
277 { \
278  if (((COND))) { \
279  CAMITK_INFO(MSG) \
280  } \
281 }
282 
283 #define CAMITK_INFO_IF_ALT(COND, MSG) \
284 { \
285  if (((COND))) { \
286  CAMITK_INFO_ALT(MSG) \
287  } \
288 }
289 
290 #define CAMITK_WARNING_IF(COND, MSG) \
291 { \
292  if (((COND))) { \
293  CAMITK_WARNING(MSG) \
294  } \
295 }
296 
297 #define CAMITK_WARNING_IF_ALT(COND, MSG) \
298 { \
299  if (((COND))) { \
300  CAMITK_WARNING_ALT(MSG) \
301  } \
302 }
303 
304 #define CAMITK_ERROR_IF(COND, MSG) \
305 { \
306  if (((COND))) { \
307  CAMITK_ERROR(MSG) \
308  } \
309 }
310 
311 #define CAMITK_ERROR_IF_ALT(COND, MSG) \
312 { \
313  if (((COND))) { \
314  CAMITK_ERROR_ALT(MSG) \
315  } \
316 }
317 
318 
319 }
320 
321 #endif // LOG_H
#define CAMITK_API
Definition: CamiTKAPI.h:49
The CamiTK logger interface provides a flexible tracing system to CamiTK applications.
Definition: InterfaceLogger.h:51
LogLevel
: how chatty should the log output be...
Definition: InterfaceLogger.h:60
This class is a log utility.
Definition: Log.h:199
Definition: Action.cpp:36