Computer Assited Medical Intervention Tool Kit  version 3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-2013 UJF-Grenoble 1, 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 {
40 // information for the user, generic information, always here
41 #define CAMITK_INFO(CLASSNAME, METHODNAME, MSG) Log("INFO", CLASSNAME, METHODNAME, MSG)
42 #define CAMITK_INFO_IF(B, CLASSNAME, METHODNAME, MSG) \
43 { \
44  if (((B))) { \
45  CAMITK_INFO(CLASSNAME, METHODNAME, MSG) \
46  } \
47 } \
48 
49 // error generated by the program (unexpectedly)
50 #define CAMITK_ERROR(CLASSNAME, METHODNAME, MSG) Log("ERROR", CLASSNAME, METHODNAME, MSG)
51 #define CAMITK_ERROR_IF(B, CLASSNAME, METHODNAME, MSG) \
52 { \
53  if ((B)) { \
54  CAMITK_ERROR(CLASSNAME, METHODNAME, MSG) \
55  } \
56 } \
57 
58 // ---------------- CAMITK_LOG_ERROR ----------------
59 #ifdef CAMITK_LOG_ERROR
60  #define CAMITK_WARNING(CLASSNAME, METHODNAME, MSG)
61  #define CAMITK_WARNING_IF(B, CLASSNAME, METHODNAME, MSG)
62  #define CAMITK_DEBUG(CLASSNAME, METHODNAME, MSG)
63  #define CAMITK_DEBUG_IF(B, CLASSNAME, METHODNAME, MSG)
64 #endif // CAMITK_LOG_ERROR
65 
66 // ---------------- CAMITK_LOG_WARNING ----------------
67 #ifdef CAMITK_LOG_WARNING
68  #define CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) Log("WARNING", CLASSNAME, METHODNAME, MSG);
69  #define CAMITK_WARNING_IF(B, CLASSNAME, METHODNAME, MSG) \
70  { \
71  if ((B)) { \
72  CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) \
73  } \
74  } \
75 
76  #define CAMITK_DEBUG(CLASSNAME, METHODNAME, MSG)
77  #define CAMITK_DEBUG_IF(B, CLASSNAME, METHODNAME, MSG)
78 #endif // CAMITK_LOG_WARNING
79 
80 
81 // ---------------- CAMITK_LOG_DEBUG ----------------
82 #ifdef CAMITK_LOG_DEBUG
83 #define CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) Log("WARNING", CLASSNAME, METHODNAME, MSG);
84 #define CAMITK_WARNING_IF(B, CLASSNAME, METHODNAME, MSG) \
85 { \
86  if ((B)) { \
87  CAMITK_WARNING(CLASSNAME, METHODNAME, MSG) \
88  } \
89 } \
90 
91 #define CAMITK_DEBUG(CLASSNAME, METHODNAME, MSG) Log("DEBUG", CLASSNAME, METHODNAME, MSG);
92 #define CAMITK_DEBUG_IF(B, CLASSNAME, METHODNAME, MSG) \
93 { \
94  if ((B)) { \
95  CAMITK_DEBUG(CLASSNAME, METHODNAME, MSG) \
96  } \
97 } \
98 
99 #endif // CAMITK_LOG_DEBUG
100 
102 #define Log(TYPE, CLASSNAME, METHODNAME, MSG) \
103 { \
104  (*Log::getLogStream()) << (TYPE); \
105  if (Log::getShowUser()) { \
106  (*Log::getLogStream()) << " " << Log::getUserInformation(); \
107  } \
108  if (Log::getShowTime()) { \
109  (*Log::getLogStream()) << " " << QDateTime::currentDateTime().toString(Qt::ISODate).toStdString(); \
110  } \
111  (*Log::getLogStream()) << " | " << (CLASSNAME) << "::" << (METHODNAME) << std::endl; \
112  (*Log::getLogStream()) << MSG << std::endl; \
113  (*Log::getLogStream()) << "-----------------------------" << std::endl; \
114  Log::getLogStream()->flush(); \
115 } \
116 
117 
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
static std::ofstream * logFilePtr
the log file
Definition: Log.h:177
#define CAMITK_API
Definition: CamiTKAPI.h:49
static bool showTimeInfo
show time info
Definition: Log.h:180
This class is a log utility.
Definition: Log.h:149