Changeset 375 for cpp/common/log.cpp
- Timestamp:
- 04/26/15 00:59:09 (8 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/log.cpp
r372 r375 3 3 // See LICENSE.txt for details. 4 4 5 #include " hmessage.h"5 #include "log.h" 6 6 #include <common/nonstd_stdio.h> 7 7 #include "stl-util.h" 8 8 #include "Convert.h" 9 9 10 const char* HMSG_LEVEL[]={"[DEBUG] ","","[WARN] ","[ERROR] ","[CRITICAL] "};10 const char* LOG_LEVEL[] = { "[DEBUG] ", "", "[WARN] ", "[ERROR] ", "[CRITICAL] " }; 11 11 12 void Hmessage(const char *o, const char *m, const char *txt, int w)12 void logMessage(const char *obj, const char *method, int level, const char *msg) 13 13 { 14 14 int line = 0; //all lines except the first one get the "..." prefix … … 16 16 do 17 17 { 18 nextsep = strchr( txt, '\n');18 nextsep = strchr(msg, '\n'); 19 19 if (nextsep == NULL) //last chunk, until the end 20 nextsep = strchr( txt, '\0');21 if ((nextsep > txt) && (nextsep[-1] == '\r'))20 nextsep = strchr(msg, '\0'); 21 if ((nextsep > msg) && (nextsep[-1] == '\r')) 22 22 nextsep--; 23 23 if (line == 0) 24 24 { 25 25 if (*nextsep == 0) //there was only one line! no need to modify it in any way. 26 _ HmessageSingleLine(o, m, txt, w);26 _logMessageSingleLine(obj, method, level, msg); 27 27 else //first line from multi-line 28 _ HmessageSingleLine(o, m, string(txt, nextsep - txt).c_str(), w);28 _logMessageSingleLine(obj, method, level, string(msg, nextsep - msg).c_str()); 29 29 } 30 30 else //consecutive lines from multi-line 31 _ HmessageSingleLine(o, m, (HMSG_MULTILINE_CONTINUATION + string(txt, nextsep - txt)).c_str(), w); //could also add line numbers like ...(3)... but let's keep the prefix short and simple31 _logMessageSingleLine(obj, method, level, (LOG_MULTILINE_CONTINUATION + string(msg, nextsep - msg)).c_str()); //could also add line numbers like ...(3)... but let's keep the prefix short and simple 32 32 line++; 33 33 if ((nextsep[0] == '\r') && (nextsep[1] == '\n')) 34 txt= nextsep + 2;34 msg = nextsep + 2; 35 35 else if (*nextsep) 36 txt= nextsep + 1;36 msg = nextsep + 1; 37 37 } while (*nextsep); 38 38 } 39 39 40 40 41 void Hprintf_va(const char *o,const char *m,int w,const char *bl,va_list va)41 void logPrintf_va(const char *obj, const char *method, int level, const char *msgf, va_list va) 42 42 { 43 string buf =ssprintf_va(bl,va);44 Hmessage(o,m,buf.c_str(),w);43 string buf = ssprintf_va(msgf, va); 44 logMessage(obj, method, level, buf.c_str()); 45 45 } 46 46 47 void Hprintf(const char *o,const char *m,int w,const char *bl, ...)47 void logPrintf(const char *obj, const char *method, int level, const char *msgf, ...) 48 48 { 49 49 va_list argptr; 50 va_start(argptr, bl);51 Hprintf_va(o,m,w,bl,argptr);50 va_start(argptr, msgf); 51 logPrintf_va(obj, method, level, msgf, argptr); 52 52 va_end(argptr); 53 53 } 54 54 55 void printH(const char *bl,...)55 void log_printf(const char *msgf, ...) 56 56 { 57 57 va_list argptr; 58 va_start(argptr, bl);59 Hprintf_va("Message","printf",HMLV_INFO,bl,argptr);58 va_start(argptr, msgf); 59 logPrintf_va("Message", "printf", LOG_INFO, msgf, argptr); 60 60 va_end(argptr); 61 61 }
Note: See TracChangeset
for help on using the changeset viewer.