Computer Assited Medical Intervention Tool Kit  version 4.0
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-2016 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
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 CAMITKLOG_H
27 #define CAMITKLOG_H
28 
29 // -- Core stuff
30 #include "CamiTKAPI.h"
31 
32 // -- stl stuff
33 #include <stdlib.h>
34 
35 // -- QT stuff
36 #include <QDateTime>
37 
38 namespace camitk {
39 // information for the user, generic information, always here.
40 #define CAMITK_INFO(CLASSNAME, METHODNAME, MSG) Log("INFO", CLASSNAME, METHODNAME, MSG)
41 #define CAMITK_INFO_IF(B, CLASSNAME, METHODNAME, MSG) \
42 { \
43  if (((B))) { \
44  CAMITK_INFO(CLASSNAME, METHODNAME, MSG) \
45  } \
46 }
47 
48 // important errors use this macro. May result in seg faulting the app. Always enabled.
49 #define CAMITK_ERROR(CLASSNAME, METHODNAME, MSG) Log("ERROR", CLASSNAME, METHODNAME, MSG)
50 #define CAMITK_ERROR_IF(B, CLASSNAME, METHODNAME, MSG) \
51 { \
52  if ((B)) { \
53  CAMITK_ERROR(CLASSNAME, METHODNAME, MSG) \
54  } \
55 }
56 
57 // ---------------- Warning and Debug default values ----------------
58 #define CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) ;
59 #define CAMITK_DEBUG(CLASSNAME, METHODNAME, MSG) ;
60 
61 // ---------------- CAMITK_LOG_WARNING ----------------
62 #ifdef CAMITK_LOG_WARNING
63 // enable log level 1 : warning
64 #undef CAMITK_WARNING
65 #define CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) Log("WARNING", CLASSNAME, METHODNAME, MSG)
66 #define CAMITK_WARNING_IF(B, CLASSNAME, METHODNAME, MSG) \
67  { \
68  if ((B)) { \
69  CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) \
70  } \
71  }
72 #endif // CAMITK_LOG_WARNING
73 
74 
75 // ---------------- CAMITK_LOG_DEBUG ----------------
76 #ifdef CAMITK_LOG_DEBUG
77 // enable log level 1 : warning
78 #undef CAMITK_WARNING
79 #define CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) Log("WARNING", CLASSNAME, METHODNAME, MSG)
80 #define CAMITK_WARNING_IF(B, CLASSNAME, METHODNAME, MSG) \
81  { \
82  if ((B)) { \
83  CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) \
84  } \
85  }
86 
87 // enable log level 2 : debug
88 #undef CAMITK_DEBUG
89 #define CAMITK_DEBUG(CLASSNAME, METHODNAME, MSG) Log("DEBUG", CLASSNAME, METHODNAME, MSG)
90 #define CAMITK_DEBUG_IF(B, CLASSNAME, METHODNAME, MSG) \
91  { \
92  if ((B)) { \
93  CAMITK_DEBUG(CLASSNAME, METHODNAME, MSG) \
94  } \
95  }
96 #endif // CAMITK_LOG_DEBUG
97 
99 #define Log(TYPE, CLASSNAME, METHODNAME, MSG) \
100 { \
101  (*camitk::Log::getLogStream()) << (TYPE); \
102  if (camitk::Log::getShowUser()) { \
103  (*camitk::Log::getLogStream()) << " " << camitk::Log::getUserInformation(); \
104  } \
105  if (camitk::Log::getShowTime()) { \
106  (*camitk::Log::getLogStream()) << " " << QDateTime::currentDateTime().toString(Qt::ISODate).toStdString(); \
107  } \
108  (*camitk::Log::getLogStream()) << " | " << (CLASSNAME) << "::" << (METHODNAME) << std::endl; \
109  (*camitk::Log::getLogStream()) << MSG << std::endl; \
110  (*camitk::Log::getLogStream()) << "-----------------------------" << std::endl; \
111  camitk::Log::getLogStream()->flush(); \
112 }
113 
150 public :
152  static void showTime(bool);
153 
155  static bool getShowTime();
156 
158  static void showUser(bool);
159 
161  static bool getShowUser();
162 
164  static void openLogFile();
165 
167  static void closeLogFile();
168 
170  static std::ostream * getLogStream();
171 
173  static std::string getUserInformation();
174 
175 private :
177  static std::ofstream * logFilePtr;
178 
180  static bool showTimeInfo;
181 
183  static bool showUserInfo;
184 };
185 
186 }
187 
188 #endif // CAMITKLOG_H
static bool showUserInfo
show user info
Definition: Log.h:183
Definition: Action.cpp:40
#define CAMITK_API
Definition: CamiTKAPI.h:49
static bool showTimeInfo
show time info
Definition: Log.h:180
static std::ofstream * logFilePtr
the log file
Definition: Log.h:177
This class is a log utility.
Definition: Log.h:149