diff options
| author | Valery Febvre <vfebvre at easter-eggs.com> | 2004-07-14 21:15:38 +0000 |
|---|---|---|
| committer | Valery Febvre <vfebvre at easter-eggs.com> | 2004-07-14 21:15:38 +0000 |
| commit | 2cf32c4f0253a835f5879b0c46358f17c4de78a2 (patch) | |
| tree | 4f5b64f0cdb91789e42eb3b3a4e117edf5b02c01 | |
| parent | a5cc9aa23784a352ebc0d816626d71bd10354c45 (diff) | |
| download | lasso-2cf32c4f0253a835f5879b0c46358f17c4de78a2.tar.gz lasso-2cf32c4f0253a835f5879b0c46358f17c4de78a2.tar.xz lasso-2cf32c4f0253a835f5879b0c46358f17c4de78a2.zip | |
New debug system with 4 levels (4 colors):
DEBUG : yellow
INFO : green
WARNING : blue
ERROR : red
if Cflag -DLASSO_DEBUG is defined, DEBUG level message are ignored.
| -rw-r--r-- | lasso/xml/debug.c | 19 | ||||
| -rw-r--r-- | lasso/xml/debug.h | 15 |
2 files changed, 19 insertions, 15 deletions
diff --git a/lasso/xml/debug.c b/lasso/xml/debug.c index 2d6b23d3..1ad2517c 100644 --- a/lasso/xml/debug.c +++ b/lasso/xml/debug.c @@ -24,7 +24,13 @@ #include <lasso/xml/debug.h> -int debug_line; +#define normal "\033[m" +#define red "\033[31m" +#define green "\033[32m" +#define yellow "\033[33m" +#define blue "\033[34m" + +int debug_line; char debug_filename[512]; char debug_function[512]; static const char *errorcode[4] = { @@ -50,7 +56,7 @@ _debug(unsigned int level, { char debug_string[1024]; char new_debug_string[2048]; - char *color; + char *color, *p; va_list args; @@ -58,9 +64,10 @@ _debug(unsigned int level, printf("DEBUG LEVEL level=%d, must be 0<=x<=3 !!!\n"); return; } - + va_start(args, format); - vsprintf(debug_string, format, args); + //vsprintf(debug_string, format, args); + vsnprintf(debug_string, sizeof(debug_string), format, args); va_end(args); switch (level) { @@ -71,6 +78,8 @@ _debug(unsigned int level, color = blue; break; case DEBUG: + color = yellow; + break; case INFO: color = green; break; @@ -80,7 +89,7 @@ _debug(unsigned int level, "%s%s%s (%s/%s:%d)\t%s", color, errorcode[level], - black, + normal, debug_filename, debug_function, debug_line, debug_string); diff --git a/lasso/xml/debug.h b/lasso/xml/debug.h index 162c7749..b497efc9 100644 --- a/lasso/xml/debug.h +++ b/lasso/xml/debug.h @@ -32,15 +32,10 @@ extern "C" { #endif /* __cplusplus */ -#define black "\033[m" -#define red "\033[31m" -#define green "\033[32m" -#define blue "\033[34m" - -#define DEBUG 0 -#define INFO 1 -#define WARNING 2 -#define ERROR 3 +#define DEBUG 0 /* for debug - print only if flags LASSO_DEBUG is defined */ +#define INFO 1 /* just print info */ +#define WARNING 2 /* non fatal errors */ +#define ERROR 3 /* criticial/fatal errors */ void set_debug_info(int line, char *filename, char *function); void _debug(unsigned int level, const char *format, ...); @@ -48,7 +43,7 @@ void _debug(unsigned int level, const char *format, ...); #if defined LASSO_DEBUG #define debug set_debug_info(__LINE__, __FILE__, __FUNCTION__); _debug #else -#define debug(level, format, ...); +#define debug(level, format, args...) if (level > DEBUG) { set_debug_info(__LINE__, __FILE__, __FUNCTION__); _debug(level, format, ##args); } #endif #ifdef __cplusplus |
