Changeset 375 for cpp/frams/loggers/loggers.h
- Timestamp:
- 04/26/15 00:59:09 (9 years ago)
- Location:
- cpp/frams/loggers
- Files:
-
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/loggers/loggers.h
r374 r375 3 3 // See LICENSE.txt for details. 4 4 5 #ifndef _ MHANDLERS_H_6 #define _ MHANDLERS_H_5 #ifndef _FRAMS_LOGGERS_H_ 6 #define _FRAMS_LOGGERS_H_ 7 7 8 8 #include <frams/util/list.h> 9 9 #include <frams/util/sstring.h> 10 #include <common/ hmessage.h>10 #include <common/log.h> 11 11 #include <common/threads.h> 12 12 13 class MessageHandlerBase;13 class LoggerBase; 14 14 15 class MessageHandlerManager15 class LoggerManager 16 16 { 17 friend class MessageHandlerBase;18 SListTempl< MessageHandlerBase*> handlers;19 void send(int level, const char *o, const char *m, const char *bl, int w);17 friend class LoggerBase; 18 SListTempl<LoggerBase*> handlers; 19 void send(int level, const char *o, const char *m, int w, const char *bl); 20 20 public: 21 int find( MessageHandlerBase *r) { return handlers.find(r); }22 int add( MessageHandlerBase *r);21 int find(LoggerBase *r) { return handlers.find(r); } 22 int add(LoggerBase *r); 23 23 void remove(int i); 24 void remove( MessageHandlerBase *r);24 void remove(LoggerBase *r); 25 25 void removeAll(); 26 void send(const char *o, const char *m, const char *bl, int w)26 void send(const char *o, const char *m, int w, const char *bl) 27 27 { 28 send(handlers.size() - 1, o, m, bl, w);28 send(handlers.size() - 1, o, m, w, bl); 29 29 } 30 ~ MessageHandlerManager() { removeAll(); }30 ~LoggerManager() { removeAll(); } 31 31 }; 32 32 33 extern THREAD_LOCAL_DECL( MessageHandlerManager, message_handler_manager_instance);33 extern THREAD_LOCAL_DECL(LoggerManager, message_handler_manager_instance); 34 34 35 35 //////////////////////////////////////// 36 36 37 class MessageHandlerBase37 class LoggerBase 38 38 { 39 friend class MessageHandlerManager;39 friend class LoggerManager; 40 40 protected: 41 MessageHandlerManager* manager;41 LoggerManager* manager; 42 42 int options; 43 43 44 44 public: 45 45 46 enum HandlerOptions46 enum LoggerOptions 47 47 { 48 48 DontBlock = 1, CannotBeBlocked = 2, Enable = 4, Paused = 8 49 49 }; 50 50 51 void Hprintf(const char *o, const char *m, int w, const char *bl, ...);52 void send(const char *o, const char *m, const char *bl, int w);51 void logPrintf(const char *o, const char *m, int w, const char *bl, ...); 52 void send(const char *o, const char *m, int w, const char *bl); 53 53 54 54 bool isEnabled() { return manager ? true : false; } … … 59 59 void resume(); 60 60 61 MessageHandlerBase(int opts = 0) :manager(NULL), options(opts)61 LoggerBase(int opts = 0) :manager(NULL), options(opts) 62 62 { 63 63 if (options&Enable) enable(); 64 64 } 65 virtual ~ MessageHandlerBase()65 virtual ~LoggerBase() 66 66 { 67 67 disable(); 68 68 } 69 69 70 virtual void handle(const char *o, const char *m, const char *bl, int w) {}70 virtual void handle(const char *o, const char *m, int w, const char *bl) {} 71 71 }; 72 72 73 73 /////////////////////////////////////////// 74 74 75 class MessageHandlerToMemory : public MessageHandlerBase75 class LoggerToMemory : public LoggerBase 76 76 { 77 77 protected: … … 81 81 public: 82 82 83 void reset() { maxlevel = HMLV_INFO - 1; errcount = warncount = storedcount = infocount = 0; msgs = 0; }83 void reset() { maxlevel = LOG_INFO - 1; errcount = warncount = storedcount = infocount = 0; msgs = 0; } 84 84 85 85 enum Options2 … … 95 95 const SString& getMessages() { return msgs; } 96 96 97 MessageHandlerToMemory(int opts = 0, int minimal_level_to_store = HMLV_ERROR) :MessageHandlerBase(opts), minleveltostore(minimal_level_to_store)97 LoggerToMemory(int opts = 0, int minimal_level_to_store = LOG_ERROR) :LoggerBase(opts), minleveltostore(minimal_level_to_store) 98 98 { 99 99 reset(); 100 100 } 101 101 102 void handle(const char *o, const char *m, const char *bl, int w);102 void handle(const char *o, const char *m, int w, const char *bl); 103 103 }; 104 104 105 class Redirecting MessageHandler : public MessageHandlerBase105 class RedirectingLogger : public LoggerBase 106 106 { 107 MessageHandlerManager *other_manager;107 LoggerManager *other_manager; 108 108 public: 109 Redirecting MessageHandler(MessageHandlerManager *other_mgr,int opts=0)110 : MessageHandlerBase(opts), other_manager(other_mgr) {}109 RedirectingLogger(LoggerManager *other_mgr,int opts=0) 110 :LoggerBase(opts), other_manager(other_mgr) {} 111 111 112 void handle(const char *o, const char *m, const char *bl, int w)112 void handle(const char *o, const char *m, int w, const char *bl) 113 113 { 114 other_manager->send(o, m, bl, w);114 other_manager->send(o, m, w, bl); 115 115 } 116 116 };
Note: See TracChangeset
for help on using the changeset viewer.