Changeset 375 for cpp/frams/loggers
- Timestamp:
- 04/26/15 00:59:09 (10 years ago)
- Location:
- cpp/frams/loggers
- Files:
-
- 6 deleted
- 4 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/loggers/loggers.cpp
r374 r375 3 3 // See LICENSE.txt for details. 4 4 5 #include " mhandlers.h"5 #include "loggers.h" 6 6 #include <common/stl-util.h> 7 7 8 void _ HmessageSingleLine(const char *o, const char *m, const char *txt, int w)8 void _logMessageSingleLine(const char *o, const char *m, int w, const char *txt) 9 9 { 10 tlsGetRef(message_handler_manager_instance).send(o, m, txt, w);10 tlsGetRef(message_handler_manager_instance).send(o, m, w, txt); 11 11 } 12 12 13 THREAD_LOCAL_DEF( MessageHandlerManager, message_handler_manager_instance);13 THREAD_LOCAL_DEF(LoggerManager, message_handler_manager_instance); 14 14 15 void MessageHandlerManager::send(int level, const char *o, const char *m, const char *bl, int w)15 void LoggerManager::send(int level, const char *o, const char *m, int w, const char *bl) 16 16 { 17 17 if (level >= handlers.size()) level = handlers.size() - 1; … … 19 19 for (int i = level; i >= 0; i--) 20 20 { 21 MessageHandlerBase *r = handlers(i);22 if ((!(r->options & MessageHandlerBase::Paused)) &&23 ((!blocked) || (r->options & MessageHandlerBase::CannotBeBlocked)))21 LoggerBase *r = handlers(i); 22 if ((!(r->options & LoggerBase::Paused)) && 23 ((!blocked) || (r->options & LoggerBase::CannotBeBlocked))) 24 24 { 25 r->handle(o, m, bl, w);26 if (!(r->options & MessageHandlerBase::DontBlock)) blocked = 1;25 r->handle(o, m, w, bl); 26 if (!(r->options & LoggerBase::DontBlock)) blocked = 1; 27 27 } 28 28 } 29 29 } 30 30 31 int MessageHandlerManager::add(MessageHandlerBase *h)31 int LoggerManager::add(LoggerBase *h) 32 32 { 33 33 h->manager = this; … … 36 36 } 37 37 38 void MessageHandlerManager::remove(int i)38 void LoggerManager::remove(int i) 39 39 { 40 MessageHandlerBase *h = handlers(i);40 LoggerBase *h = handlers(i); 41 41 h->manager = NULL; 42 42 handlers.remove(i); 43 43 } 44 44 45 void MessageHandlerManager::remove(MessageHandlerBase *h)45 void LoggerManager::remove(LoggerBase *h) 46 46 { 47 47 int i; … … 50 50 } 51 51 52 void MessageHandlerManager::removeAll()52 void LoggerManager::removeAll() 53 53 { 54 54 while (handlers.size() > 0) … … 58 58 ////////////////////////////////// 59 59 60 void MessageHandlerBase::send(const char *o, const char *m, const char *bl, int w)60 void LoggerBase::send(const char *o, const char *m, int w, const char *bl) 61 61 { 62 62 if (!isEnabled()) return; 63 63 int level = manager->find(this); 64 if (level >= 0) manager->send(level - 1, o, m, bl, w);64 if (level >= 0) manager->send(level - 1, o, m, w, bl); 65 65 } 66 66 67 void MessageHandlerBase::Hprintf(const char *o, const char *m, int w, const char *bl, ...)67 void LoggerBase::logPrintf(const char *o, const char *m, int w, const char *bl, ...) 68 68 { 69 69 if (!isEnabled()) return; … … 73 73 buf = ssprintf_va(bl, argptr); 74 74 va_end(argptr); 75 send(o, m, buf.c_str(), w);75 send(o, m, w, buf.c_str()); 76 76 } 77 77 78 78 79 void MessageHandlerBase::enable()79 void LoggerBase::enable() 80 80 { 81 81 if (isEnabled()) return; … … 83 83 } 84 84 85 void MessageHandlerBase::disable()85 void LoggerBase::disable() 86 86 { 87 87 if (!isEnabled()) return; … … 89 89 } 90 90 91 void MessageHandlerBase::pause()91 void LoggerBase::pause() 92 92 { 93 93 if (isPaused()) return; … … 95 95 } 96 96 97 void MessageHandlerBase::resume()97 void LoggerBase::resume() 98 98 { 99 99 if (!isPaused()) return; … … 103 103 ///////////////////////////////// 104 104 105 void MessageHandlerToMemory::handle(const char *o, const char *m, const char *bl, int w)105 void LoggerToMemory::handle(const char *o, const char *m, int w, const char *bl) 106 106 { 107 107 if (w > maxlevel) maxlevel = w; 108 if (w >= HMLV_INFO) infocount++;109 if (w >= HMLV_WARN) warncount++;110 if (w >= HMLV_ERROR) errcount++;108 if (w >= LOG_INFO) infocount++; 109 if (w >= LOG_WARN) warncount++; 110 if (w >= LOG_ERROR) errcount++; 111 111 112 112 if (w >= minleveltostore) … … 118 118 { 119 119 if (msgs.len() > 0) msgs += '\n'; 120 msgs += o; msgs += "::"; msgs += m; 121 msgs += " - "; msgs += bl; 120 msgs += SString::sprintf(LOG_FORMAT,LOG_LEVEL[w+1],o,m,bl); 122 121 } 123 122 } -
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 }; -
cpp/frams/loggers/loggertostdout.cpp
r374 r375 3 3 // See LICENSE.txt for details. 4 4 5 #include " stdouthandler.h"5 #include "loggertostdout.h" 6 6 #ifdef SHP 7 7 #include <FBaseSys.h> //AppLog … … 10 10 #endif 11 11 12 void MessageHandlerToStdout::handle(const char *o, const char *m, const char *bl, int w)12 void LoggerToStdout::handle(const char *o, const char *m, int w, const char *bl) 13 13 { 14 14 if (w < -1) w = -1; else if (w>3) w = 3; 15 15 #ifdef SHP 16 AppLog( HMSG_FORMAT "\n",HMSG_LEVEL[w+1],o,m,bl);16 AppLog(LOG_FORMAT "\n",LOG_LEVEL[w+1],o,m,bl); 17 17 #else 18 18 if (file) 19 file->printf( HMSG_FORMAT "\n", HMSG_LEVEL[w + 1], o, m, bl);19 file->printf(LOG_FORMAT "\n", LOG_LEVEL[w + 1], o, m, bl); 20 20 else 21 printf( HMSG_FORMAT "\n", HMSG_LEVEL[w + 1], o, m, bl);21 printf(LOG_FORMAT "\n", LOG_LEVEL[w + 1], o, m, bl); 22 22 #endif 23 23 } -
cpp/frams/loggers/loggertostdout.h
r374 r375 3 3 // See LICENSE.txt for details. 4 4 5 #ifndef _STDOUT HANDLER_H_6 #define _STDOUT HANDLER_H_5 #ifndef _STDOUT_LOGGER_H_ 6 #define _STDOUT_LOGGER_H_ 7 7 8 #include " mhandlers.h"8 #include "loggers.h" 9 9 #include <frams/virtfile/virtfile.h> 10 10 11 class MessageHandlerToStdout : public MessageHandlerBase11 class LoggerToStdout : public LoggerBase 12 12 { 13 13 VirtFILE *file; 14 14 public: 15 MessageHandlerToStdout(int opts = 0, VirtFILE *_file = NULL) :MessageHandlerBase(opts), file(_file) {}16 void handle(const char *o, const char *m, const char *bl, int w);15 LoggerToStdout(int opts = 0, VirtFILE *_file = NULL) :LoggerBase(opts), file(_file) {} 16 void handle(const char *o, const char *m, int w, const char *bl); 17 17 }; 18 18
Note: See TracChangeset
for help on using the changeset viewer.