LogTrace.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno    
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
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 // class LogTrace : public stringstream{
00147 //  private:
00148 //   stringstream trace;
00149 //   fstream    log;
00150 //  public:
00151 //   LogTrace(string logFileName=0){
00152 //    if(logFileName != ""){
00153 //     log.open(logFileName.c_str(), fstream::out);
00154 //     if(!log.is_open()){
00155 //      cout << "WIP-warning: unable to open " << logFileName << endl;
00156 //     }
00157 //    }
00158 //   }
00159 //   
00160 //   ~LogTrace(){
00161 //    if(log.is_open()){
00162 //     log.close();
00163 //    }
00164 //   }
00165 // 
00166 // // //   friend ostream& operator<<(ostream& Ostr, const LogTrace& lt);
00167 // // //   friend istream& operator>>(istream& Istr, LogTrace& lt);
00168 // 
00169 //   
00170 // //   istream& operator>>(istream& in, LogTrace& lt){
00171 // //    if (in.good()){
00172 // //     lt.trace << in;
00173 // //    }
00174 // //    return in;
00175 // //   }
00176 // //   
00177 // //   void flush (){
00178 // //    cout << trace;
00179 // //    fflush(stdout);
00180 // //   }
00181 // // 
00182 // //   
00183 // //   friend ostream& operator<<(ostream&, const LogTrace&){
00184 // //    out << "(" << c.myReal << "," << c.myImag << ")";
00185 // //    return out;
00186 // //    
00187 // //   }
00188 // };
00189 
00190 // had to move code to cpp, because include CommonOptions.h resulted in circular include depend.
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 

Generated on Mon Feb 20 07:01:06 2017 for MIP by  doxygen 1.5.6