Changeset 375 for cpp/common
- Timestamp:
- 04/26/15 00:59:09 (10 years ago)
- Location:
- cpp/common
- Files:
-
- 3 edited
- 2 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 } -
cpp/common/log.h
r372 r375 3 3 // See LICENSE.txt for details. 4 4 5 #ifndef _ HMESSAGE_H_6 #define _ HMESSAGE_H_5 #ifndef _COMMON_LOG_H_ 6 #define _COMMON_LOG_H_ 7 7 8 8 #include <stdarg.h> 9 9 10 extern const char* HMSG_LEVEL[];11 #define HMSG_FORMAT "%s%s.%s: %s"12 #define HMSG_MULTILINE_CONTINUATION "..."10 extern const char* LOG_LEVEL[]; 11 #define LOG_FORMAT "%s%s.%s: %s" 12 #define LOG_MULTILINE_CONTINUATION "..." 13 13 14 void Hprintf(const char *o,const char *m,int w,const char *bl, ...);15 void Hprintf_va(const char *o,const char *m,int w,const char *bl,va_list va); //a different name than Hprintf - otherwise the compiler could confuse the "string" parameter with va_list and could call the wrong function16 void printH(const char *bl,...); //a shorthand for printf (a different name again to avoid the risk of confusion with the two functions above. This would be unlikely but possible when the argument types would match)17 void Hmessage(const char *o,const char *m,const char *txt,int w);18 14 19 void _HmessageSingleLine(const char *o,const char *m,const char *txt,int w); //don't call this directly - it is used internally 15 void logPrintf(const char *obj, const char *method, int level, const char *msgf, ...); 16 void logPrintf_va(const char *obj, const char *method, int level, const char *msgf, va_list va); //a different name than logPrintf - otherwise the compiler could confuse the "string" parameter with va_list and could call the wrong function 17 void log_printf(const char *msgf, ...); //a shorthand for printf (a different name again to avoid the risk of confusion with the two functions above. This would be unlikely but possible when the argument types would match) 18 void logMessage(const char *obj, const char *method, int level, const char *msg); 20 19 21 #define HMLV_DEBUG -1 22 #define HMLV_INFO 0 23 #define HMLV_WARN 1 24 #define HMLV_ERROR 2 25 #define HMLV_CRITICAL 3 20 void _logMessageSingleLine(const char *obj, const char *method, int level, const char *msg); //don't call this directly - it is used internally 26 21 27 /* 28 w: weight (importance) of a message 29 -1:debugging information, not needed for final users 30 0: information 31 1: warning or corrected error 32 2: uncorrected error. can cause malfunction 33 3: serious error, causes side effects. user should save what can be saved and restart the application34 */ 22 23 24 //level (importance) of a message 25 #define LOG_DEBUG -1 //debugging information, not needed for final users 26 #define LOG_INFO 0 //information 27 #define LOG_WARN 1 //warning or corrected error 28 #define LOG_ERROR 2 //uncorrected error, can cause malfunction 29 #define LOG_CRITICAL 3 //serious error, causes side effects. User should save what can be saved and restart the application 35 30 36 31 #endif -
cpp/common/nonstd_math.cpp
r372 r375 81 81 // But it was resolved by restarting windows and cleaning all intermediate compilation files :o (restarting windows was the key element! restarting BC++Builder and deleting files would not help) 82 82 83 #include " hmessage.h"83 #include "log.h" 84 84 85 85 unsigned int fp_control_word_std; … … 89 89 { 90 90 //unsigned int was=_clear87(); 91 // Hprintf("","fpExceptInit",HMLV_INFO,"control87 status before clear was %08x", was);91 //logPrintf("","fpExceptInit",LOG_INFO,"control87 status before clear was %08x", was); 92 92 fp_control_word_std=_control87(0, 0); //4978 = 1001101110010 93 93 // Make the new fp env same as the old one, except for the changes we're going to make … … 98 98 { 99 99 unsigned int was=_clear87(); //trzeba czyscic zeby nie bylo exception... 100 // Hprintf("","fpExceptEnable ",HMLV_INFO,"control87 status before clear was %08x", was);100 //logPrintf("","fpExceptEnable ",LOG_INFO,"control87 status before clear was %08x", was); 101 101 _control87(fp_control_word_std, 0xffffffff); 102 // Hprintf("","fpExceptEnable ",HMLV_INFO,"control87 flags are %08x", _control87(0, 0)); //kontrola co sie ustawilo102 //logPrintf("","fpExceptEnable ",LOG_INFO,"control87 flags are %08x", _control87(0, 0)); //kontrola co sie ustawilo 103 103 } 104 104 … … 106 106 { 107 107 unsigned int was=_clear87(); //trzeba czyscic zeby nie bylo exception... 108 // Hprintf("","fpExceptDisable",HMLV_INFO,"control87 status before clear was %08x", was);108 //logPrintf("","fpExceptDisable",LOG_INFO,"control87 status before clear was %08x", was); 109 109 _control87(fp_control_word_muted, 0xffffffff); 110 // Hprintf("","fpExceptDisable",HMLV_INFO,"control87 flags are %08x", _control87(0, 0)); //kontrola co sie ustawilo110 //logPrintf("","fpExceptDisable",LOG_INFO,"control87 flags are %08x", _control87(0, 0)); //kontrola co sie ustawilo 111 111 } 112 112 -
cpp/common/nonstd_stdio.cpp
r374 r375 242 242 243 243 #ifdef __ANDROID__ 244 #include " hmessage.h"244 #include "log.h" 245 245 #include "nonstd.h" 246 246 #include "nonstd_stl.h" … … 248 248 { 249 249 string respath=getAppResourcesDir(); 250 // printH("Opening '%s', mode='%s'",path,mode);251 // printH("getAppResourcesDir()='%s'",respath.c_str());250 //log_printf("Opening '%s', mode='%s'",path,mode); 251 //log_printf("getAppResourcesDir()='%s'",respath.c_str()); 252 252 NvFile *rfile=NULL; //can only read 253 253 FILE *rwfile=NULL; … … 256 256 path+=respath.length(); //strip the prefix, we need a relative path in assets 257 257 if (strstr(mode,"w")) 258 printH("Warning: attempt to open a read-only resource '%s' in writable mode '%s'",path,mode);258 log_printf("Warning: attempt to open a read-only resource '%s' in writable mode '%s'",path,mode); 259 259 rfile=NvFOpen(path); //"mode" not supported! can only read 260 // printH("Opened RES file as %p",rfile);260 //log_printf("Opened RES file as %p",rfile); 261 261 if (rfile==NULL) return NULL; 262 262 } else //a "normal" access (HOME) 263 263 { 264 264 rwfile=fopen(path,mode); 265 // printH("Opened HOME file as %p",rwfile);265 //log_printf("Opened HOME file as %p",rwfile); 266 266 if (rwfile==NULL) return NULL; 267 267 } -
cpp/common/stl-util.cpp
r374 r375 9 9 #include "Convert.h" 10 10 #include "nonstd.h" 11 #include " hmessage.h"11 #include "log.h" 12 12 #include <assert.h> 13 13 #ifdef USE_VIRTFILE … … 103 103 } 104 104 if (warn_on_missing_file && !ok) 105 Hprintf("stl-util", "readCompleteFile", HMLV_WARN, "Couldn't open file '%s'", filename);105 logPrintf("stl-util", "readCompleteFile", LOG_WARN, "Couldn't open file '%s'", filename); 106 106 return ok; 107 107 } … … 129 129 } 130 130 if (warn_on_fail && !ok) 131 Hprintf("stl-util", "writeCompleteFile", HMLV_WARN, "couldn't write file '%s'", filename);131 logPrintf("stl-util", "writeCompleteFile", LOG_WARN, "couldn't write file '%s'", filename); 132 132 return ok; 133 133 }
Note: See TracChangeset
for help on using the changeset viewer.