LogTrace.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00030
00034
00036
00037
00038
00039 #ifndef __LOG_TRACE_H_
00040 #define __LOG_TRACE_H_
00041
00042 #ifdef MIP_HOST_APPLE
00043 #include <applePatch.h>
00044 #endif
00045
00046 #include <stdio.h>
00047 #include <stdlib.h>
00048 #include <assert.h>
00049 #include <iostream>
00050 #include <string>
00051 #include <sstream>
00052 #include <fstream>
00053
00054 #define COL_NORMAL "\033[0m"
00055 #define COL_BLACK "\033[22;30m"
00056 #define COL_RED "\033[22;31m"
00057 #define COL_GREEN "\033[22;32m"
00058 #define COL_BROWN "\033[22;33m"
00059 #define COL_BLUE "\033[22;34m"
00060 #define COL_MAGENTA "\033[22;35m"
00061 #define COL_CYAN "\033[22;36m"
00062 #define COL_GRAY "\033[22;37m"
00063 #define COL_DARK_GRAY "\033[01;30m"
00064 #define COL_LIGHT_RED "\033[01;31m"
00065 #define COL_LIGHT_GREEN "\033[01;32m"
00066 #define COL_YELLOW "\033[01;33m"
00067 #define COL_LIGHT_BLUE "\033[01;34m"
00068 #define COL_LIGHT_MAGENTA "\033[01;35m"
00069 #define COL_LIGH_CYAN "\033[01;36m"
00070 #define COL_WHITE "\033[01;37m"
00071
00072 #define COLORIZE(string,NEW_COLOR) NEW_COLOR << string << COL_NORMAL
00073
00074 #define MIP_DEBUG_STATIC(debLevel,_staticLevel,message) \
00075 { \
00076 if(debLevel <= _staticLevel) { \
00077 std::cout << "\033[01;31m" << "[MIPDEBUG] " << "\033[0m" << message << std::endl; \
00078 } \
00079 }
00080
00081 #define MIP_DEBUG(debLevel,message) \
00082 { \
00083 if(debLevel <= getDebugLevel()) { \
00084 stringstream MIP_DEBUG_ss; \
00085 MIP_DEBUG_ss << message; \
00086 debug(debLevel,MIP_DEBUG_ss.str()); \
00087 } \
00088 }
00089
00090 #define MIP_INFO(message) \
00091 { \
00092 stringstream MIP_INFO_ss; \
00093 MIP_INFO_ss << message; \
00094 info(MIP_INFO_ss.str()); \
00095 }
00096
00097 #define MIP_WARNING(message) \
00098 { \
00099 stringstream MIP_WARNING_ss; \
00100 MIP_WARNING_ss << message; \
00101 warning(MIP_WARNING_ss.str()); \
00102 }
00103
00104 #define MIP_FATAL(message) \
00105 { \
00106 stringstream MIP_FATAL_ss; \
00107 MIP_FATAL_ss << message; \
00108 fatal(MIP_FATAL_ss.str()); \
00109 }
00110
00111 #define MIP_STATIC_DEBUG(classname,debLevel,message) \
00112 { \
00113 stringstream MIP_DEBUG_ss; \
00114 MIP_DEBUG_ss << "(" << classname << "): " << message; \
00115 LogTrace::debug(debLevel,MIP_DEBUG_ss.str()); \
00116 }
00117
00118 #define MIP_STATIC_INFO(classname, message) \
00119 { \
00120 stringstream MIP_INFO_ss; \
00121 MIP_INFO_ss << "(" << classname << "): " << message; \
00122 LogTrace::info(MIP_INFO_ss.str()); \
00123 }
00124
00125 #define MIP_STATIC_WARNING(classname,message) \
00126 { \
00127 stringstream MIP_WARNING_ss; \
00128 MIP_WARNING_ss << "(" << classname << "): " << message; \
00129 LogTrace::warning(MIP_WARNING_ss.str()); \
00130 }
00131
00132 #define MIP_STATIC_FATAL(classname,message) \
00133 { \
00134 stringstream MIP_FATAL_ss; \
00135 MIP_FATAL_ss << "(" << classname << "): " << message; \
00136 LogTrace::fatal(MIP_FATAL_ss.str()); \
00137 }
00138
00139 using namespace std;
00140
00141 extern stringstream tstream;
00142
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 class LogTrace {
00192
00193 public:
00196 static void fatal(const string& fatalMessage);
00197
00200 static void warning(const string& warningMessage);
00201
00204 static void info(const string& infoMessage);
00205
00208 static void debug(int level, const string& infoMessage, int customLevel=0);
00209
00212 static int getDebugLevel(int customLevel);
00213 };
00214
00219 class MIPObject{
00220 private:
00221 int _customDebugLevel;
00222 public:
00223
00224 MIPObject(){
00225 _customDebugLevel = 0;
00226 }
00227
00231 virtual string getObjectName() const=0;
00232
00233
00236 void fatal(const string& fatalMessage) const {
00237 stringstream ss;
00238 ss << "(" << getObjectName() << "): " << fatalMessage;
00239 LogTrace::fatal(ss.str());
00240 }
00241
00242
00245 void warning(const string& warningMessage) const {
00246 stringstream ss;
00247 ss << "(" << getObjectName() << "): " << warningMessage;
00248 LogTrace::warning(ss.str());
00249 }
00250
00253 void info(const string& infoMessage) const {
00254 stringstream ss;
00255 ss << "(" << getObjectName() << "): " << infoMessage;
00256 LogTrace::info(ss.str());
00257 }
00258
00262 void debug(int level, const string& debugMessage) const {
00263 stringstream ss;
00264 ss << "(" << getObjectName() << "): " << debugMessage;
00265 LogTrace::debug(level,ss.str(),_customDebugLevel);
00266 }
00267
00270 void setCustomDebugLevel(int customDebugLevel){
00271 _customDebugLevel = customDebugLevel;
00272 }
00273
00275 int getDebugLevel(){
00276 return LogTrace::getDebugLevel(_customDebugLevel);
00277 }
00278 };
00279
00280
00281
00282
00283
00284 #endif
00285
00286
00287