00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef BLOGGER_H
00012 #define BLOGGER_H
00013
00020
00021 #include <stdio.h>
00022 #include <string>
00023 #include <deque>
00024 #include <DSGUI/BVirtualFile.h>
00025
00026
00027
00028
00030 typedef enum {
00031 LOG_FATAL = 0,
00032 LOG_CRIT = 1,
00033 LOG_ERROR = 2,
00034 LOG_WARN = 3,
00035 LOG_INFO = 4,
00036 LOG_BLAH = 5
00037 } LogLevel;
00038
00040 #define LOG(level, txt...) BLoggerManager::get()->log(level, txt)
00041
00049 class BLogger {
00050 public:
00051 virtual ~BLogger();
00052
00053
00061 virtual void log(LogLevel level, const std::string& text) = 0;
00062 };
00063
00064
00070 class BFileLogger: public BLogger {
00071 public:
00078 BFileLogger(const std::string& filename);
00079 virtual ~BFileLogger();
00080
00082 virtual void log(LogLevel level, const std::string& text);
00083 private:
00084 BVirtualFile* file;
00085 std::string filename;
00086 };
00087
00093 class BStdoutLogger: public BLogger {
00094 public:
00095 virtual ~BStdoutLogger();
00096 virtual void log(LogLevel level, const std::string& text);
00097 };
00098
00118 class BLoggerManager {
00119 public:
00121 static BLoggerManager* get();
00122 ~BLoggerManager();
00123
00125 void log(LogLevel level, const char* format, ...);
00126
00133 void setLogLevel(LogLevel level);
00134
00136 void addLogger(BLogger* logger);
00137
00139 void setWakeOnLog(bool wakeOnLog);
00140
00142 bool wakesOnLog() { return wakeOnLog; }
00143
00150 void setScreenSaverResetFunction(void (*fn)(void*), void* arg);
00151
00152 private:
00153 BLoggerManager();
00154 static BLoggerManager* singleton;
00155 std::deque<BLogger*> loggers;
00156 BStdoutLogger* defaultLogger;
00157 LogLevel level;
00158 bool wakeOnLog;
00159 void (*ssResetFn)(void*); void *ssResetArg;
00160 };
00161
00162 #endif