From 239c1d1ebb8fb4a34820fa85f9cdbbace33b608f Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 5 Jun 2014 09:57:20 +0200 Subject: [PATCH] Updated defines.h for better debug messages, changed DLVL_DEVEL level into DLVL_INFO (old level still exists for compatibility). --- lib/defines.h | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/defines.h b/lib/defines.h index 1e30ef9c..15c673ba 100644 --- a/lib/defines.h +++ b/lib/defines.h @@ -6,6 +6,7 @@ #define DLVL_ERROR 2 // Only messages about errors and failed operations. #define DLVL_WARN 3 // Warnings, errors, and fail messages. #define DLVL_DEVEL 4 // All of the above, plus status messages handy during development. + #define DLVL_INFO 4 // All of the above, plus status messages handy during development. #define DLVL_MEDIUM 5 // Slightly more than just development-level messages. #define DLVL_HIGH 6 // Verbose debugging messages. #define DLVL_VERYHIGH 7 // Very verbose debugging messages. @@ -16,19 +17,36 @@ #include #include - #include #include "config.h" - extern char * program_invocation_short_name; - static const char* DBG_LVL_LIST[] = {"NONE","FAIL","ERROR","WARN","DEVEL","MEDIUM","HIGH","VERYHIGH","EXTREME","INSANE","DONTEVEN"}; - #define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s|%s|%d|%s:%d|" msg "\n", DBG_LVL_LIST[lvl], program_invocation_short_name, getpid(), __FILE__, __LINE__, ##__VA_ARGS__);} - + static const char* DBG_LVL_LIST[] = {"NONE","FAIL","ERROR","WARN","INFO","MEDIUM","HIGH","VERYHIGH","EXTREME","INSANE","DONTEVEN"}; + + #ifdef __GNUC__ + #include + extern char * program_invocation_short_name; + + #if DEBUG >= DLVL_DEVEL + #define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s|%s|%d|%s:%d|" msg "\n", DBG_LVL_LIST[lvl], program_invocation_short_name, getpid(), __FILE__, __LINE__, ##__VA_ARGS__);} + #else + #define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s|%s|%d||" msg "\n", DBG_LVL_LIST[lvl], program_invocation_short_name, getpid(), ##__VA_ARGS__);} + #endif + #else + #if DEBUG >= DLVL_DEVEL + #define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s||%d|%s:%d|" msg "\n", DBG_LVL_LIST[lvl], getpid(), __FILE__, __LINE__, ##__VA_ARGS__);} + #else + #define DEBUG_MSG(lvl, msg, ...) if (Util::Config::printDebugLevel >= lvl){fprintf(stderr, "%s||%d||" msg "\n", DBG_LVL_LIST[lvl], getpid(), ##__VA_ARGS__);} + #endif + #endif + #else #define DEBUG_MSG(lvl, msg, ...) // Debugging disabled. #endif + + #define FAIL_MSG(msg, ...) DEBUG_MSG(DLVL_FAIL, msg, ##__VA_ARGS__) + #define ERROR_MSG(msg, ...) DEBUG_MSG(DLVL_ERROR, msg, ##__VA_ARGS__) + #define WARN_MSG(msg, ...) DEBUG_MSG(DLVL_WARN, msg, ##__VA_ARGS__) + #define DEVEL_MSG(msg, ...) DEBUG_MSG(DLVL_DEVEL, msg, ##__VA_ARGS__) + #define INFO_MSG(msg, ...) DEBUG_MSG(DLVL_DEVEL, msg, ##__VA_ARGS__) + #endif - - -//include errno.h -//program_invocation_short_name