Changeset 511
- Timestamp:
- 05/23/16 13:48:45 (8 years ago)
- Location:
- cpp/common
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/common/log.cpp
r375 r511 9 9 10 10 const char* LOG_LEVEL[] = { "[DEBUG] ", "", "[WARN] ", "[ERROR] ", "[CRITICAL] " }; 11 12 void logMessage(const char *obj, const char *method, int level, const char *msg)13 {14 int line = 0; //all lines except the first one get the "..." prefix15 const char* nextsep;16 do17 {18 nextsep = strchr(msg, '\n');19 if (nextsep == NULL) //last chunk, until the end20 nextsep = strchr(msg, '\0');21 if ((nextsep > msg) && (nextsep[-1] == '\r'))22 nextsep--;23 if (line == 0)24 {25 if (*nextsep == 0) //there was only one line! no need to modify it in any way.26 _logMessageSingleLine(obj, method, level, msg);27 else //first line from multi-line28 _logMessageSingleLine(obj, method, level, string(msg, nextsep - msg).c_str());29 }30 else //consecutive lines from multi-line31 _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 simple32 line++;33 if ((nextsep[0] == '\r') && (nextsep[1] == '\n'))34 msg = nextsep + 2;35 else if (*nextsep)36 msg = nextsep + 1;37 } while (*nextsep);38 }39 40 11 41 12 void logPrintf_va(const char *obj, const char *method, int level, const char *msgf, va_list va) -
cpp/common/log.h
r375 r511 18 18 void logMessage(const char *obj, const char *method, int level, const char *msg); 19 19 20 void _logMessageSingleLine(const char *obj, const char *method, int level, const char *msg); //don't call this directly - it is used internally21 22 23 20 24 21 //level (importance) of a message -
cpp/common/loggers/loggers.cpp
r452 r511 5 5 #include "loggers.h" 6 6 #include <common/stl-util.h> 7 #include <string.h> 7 8 8 void _logMessageSingleLine(const char *obj, const char *method, int level, const char *msg)9 void logMessage(const char *obj, const char *method, int level, const char *msg) 9 10 { 10 11 tlsGetRef(message_handler_manager_instance).send(obj, method, level, msg); … … 101 102 } 102 103 104 void LoggerBase::handle(const char *obj, const char *method, int level, const char *msg) 105 { 106 int line = 0; //all lines except the first one get the "..." prefix 107 const char* nextsep; 108 do 109 { 110 nextsep = strchr(msg, '\n'); 111 if (nextsep == NULL) //last chunk, until the end 112 nextsep = strchr(msg, '\0'); 113 if ((nextsep > msg) && (nextsep[-1] == '\r')) 114 nextsep--; 115 if (line == 0) 116 { 117 if (*nextsep == 0) //there was only one line! no need to modify it in any way. 118 handleSingleLine(obj, method, level, msg); 119 else //first line from multi-line 120 handleSingleLine(obj, method, level, string(msg, nextsep - msg).c_str()); 121 } 122 else //consecutive lines from multi-line 123 handleSingleLine(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 124 line++; 125 if ((nextsep[0] == '\r') && (nextsep[1] == '\n')) 126 msg = nextsep + 2; 127 else if (*nextsep) 128 msg = nextsep + 1; 129 } while (*nextsep); 130 } 131 103 132 ///////////////////////////////// 104 133 -
cpp/common/loggers/loggers.h
r452 r511 71 71 } 72 72 73 virtual void handle(const char *obj, const char *method, int level, const char *msg) {} 73 virtual void handle(const char *obj, const char *method, int level, const char *msg); ///< implemented by loggers accepting multiline messages. if not implemented, the default handle() splits multiline text into single lines and calls handleSingleLine() 74 virtual void handleSingleLine(const char *obj, const char *method, int level, const char *msg) {} ///< implemented by loggers expecting single line messages 74 75 }; 75 76 -
cpp/common/loggers/loggertostdout.cpp
r397 r511 27 27 } 28 28 29 void LoggerToStdout::handle (const char *obj, const char *method, int level, const char *msg)29 void LoggerToStdout::handleSingleLine(const char *obj, const char *method, int level, const char *msg) 30 30 { 31 31 if (level < -1) level = -1; else if (level>3) level = 3; -
cpp/common/loggers/loggertostdout.h
r397 r511 14 14 public: 15 15 LoggerToStdout(int opts = 0, VirtFILE *_file = NULL); 16 void handle (const char *obj, const char *method, int level, const char *msg);16 void handleSingleLine(const char *obj, const char *method, int level, const char *msg); 17 17 18 18 static const char* default_log_format[];
Note: See TracChangeset
for help on using the changeset viewer.