Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

BLogger.h

Go to the documentation of this file.
00001 // BLogger.h (this is -*- C++ -*-)
00002 // 
00003 // \author: Bjoern Giesler <bjoern@giesler.de>
00004 // 
00005 // 
00006 // $Author: giesler $
00007 // $Locker$
00008 // $Revision$
00009 // $Date: 2002-08-19 10:41:28 +0200 (Mon, 19 Aug 2002) $
00010 
00011 #ifndef BLOGGER_H
00012 #define BLOGGER_H
00013 
00020 /* system includes */
00021 #include <stdio.h>
00022 #include <string>
00023 #include <deque>
00024 #include <DSGUI/BVirtualFile.h>
00025 
00026 /* my includes */
00027 /* (none) */
00028 
00030 typedef enum {
00031   LOG_FATAL = 0, // Fatal error
00032   LOG_CRIT = 1,  // Critical error
00033   LOG_ERROR = 2, // Regular error
00034   LOG_WARN = 3,  // Warning
00035   LOG_INFO = 4,  // Informational
00036   LOG_BLAH = 5   // Everything else
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 /* BLOGGER_H */

Generated on Thu Feb 14 08:32:14 2008 for libDSFTP by doxygen1.3-rc3