openModeller
Version 1.4.0
|
00001 00028 #ifndef _LOGHH_ 00029 #define _LOGHH_ 00030 00031 #include <openmodeller/os_specific.hh> 00032 #include <openmodeller/om_defs.hh> 00033 00034 #include <iostream> 00035 #include <fstream> 00036 #include <string> 00037 #include <stdarg.h> 00038 #include <stdio.h> 00039 00040 /****************************************************************/ 00041 /****************************** Log *****************************/ 00042 00048 class dllexp Log 00049 { 00050 public: 00052 static Log * instance(); 00053 00054 typedef enum { 00055 Debug =0, 00056 Default =1, 00057 Info =2, 00058 Warn =3, 00059 Error =4 00060 } Level; 00061 00062 #ifndef SWIG 00063 class LogCallback { 00064 public: 00065 virtual ~LogCallback(){}; 00066 virtual void operator()( Level level, const std::string& msg ) = 0; 00067 }; 00068 00069 class OstreamCallback : public LogCallback { 00070 public: 00071 OstreamCallback( std::ostream& os ); 00072 void operator()( Level level, const std::string& msg ); 00073 private: 00074 std::ostream& os; 00075 }; 00076 #endif 00077 00078 protected: 00082 Log( ); 00083 00084 public: 00085 00087 static std::string format( const char *fmt, ... ); 00088 00089 ~Log(); 00090 00097 void set( Level level, std::string fileName, char const *pref="" ); 00098 00104 void setCallback( LogCallback *lc ); 00105 00107 void setLevel( Level level ) { _level = level; } 00108 00110 void setPrefix( const char *pref ); 00111 00112 void debug( const char *format, ... ); 00113 void info ( const char *format, ... ); 00114 void warn ( const char *format, ... ); 00115 void error( const char *format, ... ); 00116 00118 void operator()( const char *format, ... ); 00119 00120 private: 00121 00122 //write log out to callback 00123 void FormatAndWrite( Log::LogCallback& lc, Log::Level level, std::string pref, const char* format, va_list ap ); 00124 00125 static Log * mpInstance; 00126 00127 LogCallback* callback; 00128 00129 Level _level; 00130 00131 std::string _pref; 00132 00133 bool _deleteCallback; // flag indicating if the callback should be deleted by Log 00134 }; 00135 00136 #endif 00137