Changeset 378 for cpp/frams/loggers/loggers.cpp
- Timestamp:
- 04/27/15 04:44:23 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/loggers/loggers.cpp
r375 r378 6 6 #include <common/stl-util.h> 7 7 8 void _logMessageSingleLine(const char *o , const char *m, int w, const char *txt)8 void _logMessageSingleLine(const char *obj, const char *method, int level, const char *msg) 9 9 { 10 tlsGetRef(message_handler_manager_instance).send(o , m, w, txt);10 tlsGetRef(message_handler_manager_instance).send(obj, method, level, msg); 11 11 } 12 12 13 13 THREAD_LOCAL_DEF(LoggerManager, message_handler_manager_instance); 14 14 15 void LoggerManager::send(int level, const char *o, const char *m, int w, const char *bl)15 void LoggerManager::send(int position, const char *obj, const char *method, int level, const char *msg) 16 16 { 17 if ( level >= handlers.size()) level = handlers.size() - 1;18 bool blocked = 0;19 for (int i = level; i >= 0; i--)17 if (position >= (int)loggers.size()) position = loggers.size() - 1; 18 bool blocked = false; 19 for (int i = position; i >= 0; i--) 20 20 { 21 LoggerBase * r = handlers(i);22 if ((!( r->options & LoggerBase::Paused)) &&23 ((!blocked) || ( r->options & LoggerBase::CannotBeBlocked)))21 LoggerBase *logger = loggers[i]; 22 if ((!(logger->options & LoggerBase::Paused)) && 23 ((!blocked) || (logger->options & LoggerBase::CannotBeBlocked))) 24 24 { 25 r->handle(o, m, w, bl);26 if (!( r->options & LoggerBase::DontBlock)) blocked = 1;25 logger->handle(obj, method, level, msg); 26 if (!(logger->options & LoggerBase::DontBlock)) blocked = true; 27 27 } 28 28 } 29 29 } 30 30 31 int LoggerManager::add(LoggerBase * h)31 int LoggerManager::add(LoggerBase *logger) 32 32 { 33 h->manager = this;34 handlers += h;35 return handlers.size() - 1;33 logger->manager = this; 34 loggers.push_back(logger); 35 return loggers.size() - 1; 36 36 } 37 37 38 38 void LoggerManager::remove(int i) 39 39 { 40 LoggerBase *h = handlers(i);40 LoggerBase *h = loggers[i]; 41 41 h->manager = NULL; 42 handlers.remove(i);42 loggers.erase(loggers.begin() + i); 43 43 } 44 44 45 void LoggerManager::remove(LoggerBase * h)45 void LoggerManager::remove(LoggerBase *logger) 46 46 { 47 int i ;48 if ( (i = handlers.find(h)) < 0) return;49 remove(i);47 int index = find(logger); 48 if (index >= 0) 49 remove(index); 50 50 } 51 51 52 52 void LoggerManager::removeAll() 53 53 { 54 while ( handlers.size() > 0)55 remove( handlers.size() - 1);54 while (loggers.size() > 0) 55 remove(loggers.size() - 1); 56 56 } 57 57 58 58 ////////////////////////////////// 59 59 60 void LoggerBase::send(const char *o , const char *m, int w, const char *bl)60 void LoggerBase::send(const char *obj, const char *method, int level, const char *msg) 61 61 { 62 62 if (!isEnabled()) return; 63 int level= manager->find(this);64 if ( level >= 0) manager->send(level - 1, o, m, w, bl);63 int position = manager->find(this); 64 if (position >= 0) manager->send(position - 1, obj, method, level, msg); 65 65 } 66 66 67 void LoggerBase::logPrintf(const char *o , const char *m, int w, const char *bl, ...)67 void LoggerBase::logPrintf(const char *obj, const char *method, int level, const char *msg, ...) 68 68 { 69 69 if (!isEnabled()) return; 70 70 string buf; 71 71 va_list argptr; 72 va_start(argptr, bl);73 buf = ssprintf_va( bl, argptr);72 va_start(argptr, msg); 73 buf = ssprintf_va(msg, argptr); 74 74 va_end(argptr); 75 send(o , m, w, buf.c_str());75 send(obj, method, level, buf.c_str()); 76 76 } 77 77 … … 103 103 ///////////////////////////////// 104 104 105 void LoggerToMemory::handle(const char *o , const char *m, int w, const char *bl)105 void LoggerToMemory::handle(const char *obj, const char *method, int level, const char *msg) 106 106 { 107 if ( w > maxlevel) maxlevel = w;108 if ( w>= LOG_INFO) infocount++;109 if ( w>= LOG_WARN) warncount++;110 if ( w>= LOG_ERROR) errcount++;107 if (level > maxlevel) maxlevel = level; 108 if (level >= LOG_INFO) infocount++; 109 if (level >= LOG_WARN) warncount++; 110 if (level >= LOG_ERROR) errcount++; 111 111 112 if ( w>= minleveltostore)112 if (level >= minleveltostore) 113 113 { 114 114 storedcount++; 115 115 if (options & (StoreFirstMessage | StoreAllMessages)) 116 116 { 117 if (!((options&StoreFirstMessage) && (msgs.len () > 0)))117 if (!((options&StoreFirstMessage) && (msgs.length() > 0))) 118 118 { 119 if (msgs.len () > 0) msgs += '\n';120 msgs += SString::sprintf(LOG_FORMAT,LOG_LEVEL[w+1],o,m,bl);119 if (msgs.length() > 0) msgs += '\n'; 120 msgs += ssprintf(LOG_FORMAT, LOG_LEVEL[level + 1], obj, method, msg); 121 121 } 122 122 }
Note: See TracChangeset
for help on using the changeset viewer.