00001 00006 #ifndef GENETIK_UTIL_LOG 00007 #define GENETIK_UTIL_LOG 00008 00009 #include <string> 00010 #include <iosfwd> 00011 00012 using std::string; 00013 using std::ostream; 00014 00015 namespace genetiK 00016 { 00017 namespace util 00018 { 00024 typedef enum{ 00027 DEBUG, 00030 INFO, 00033 WARN, 00036 ERROR, 00040 FATAL, 00044 NONE 00045 } ELogLevel; 00046 00056 class Log 00057 { 00058 private: 00059 Log(); 00060 00061 Log(const Log&) {} 00062 00063 Log& operator= (const Log&) { return *self; } 00064 00065 virtual ~Log(); 00066 00067 static Log* self; 00068 00069 ELogLevel threshold; 00070 00071 ostream* target; 00072 00073 public: 00080 static Log* getInstance(); 00081 00084 static void deleteInstance(); 00085 00091 void setLevel (ELogLevel level) { threshold = level; } 00092 00098 ELogLevel getLevel() const { return threshold; } 00099 00104 int setTarget (ostream* targetStream); 00105 00112 int setTarget (const char* filename, bool append); 00113 00117 ostream* getTarget() const { return target; } 00118 00127 int output(ELogLevel level, const string& message); 00128 00134 int debug(const string& message) { return output(DEBUG, message); } 00135 00141 int info(const string& message) { return output(INFO, message); } 00142 00148 int warn(const string& message) { return output(WARN, message); } 00149 00155 int error(const string& message) { return output(ERROR, message); } 00156 00162 int fatal(const string& message) { return output(FATAL, message); } 00163 00168 bool isDebugEnabled() const { return threshold <= DEBUG; } 00169 00174 bool isInfoEnabled() const { return threshold <= INFO; } 00175 00180 bool isWarnEnabled() const { return threshold <= WARN; } 00181 00186 bool isErrorEnabled() const { return threshold <= ERROR; } 00187 00192 bool isFatalEnabled() const { return threshold <= FATAL; } 00193 00199 bool isEnabled(ELogLevel level) const { return threshold <= level; } 00200 00201 }; 00202 00203 } 00204 } 00205 00206 #endif