diff --git a/common/include/common/debug.h b/common/include/common/debug.h index 10518326..aa6db868 100644 --- a/common/include/common/debug.h +++ b/common/include/common/debug.h @@ -32,6 +32,7 @@ enum DebugLevel { + DEBUG_LEVEL_NONE, DEBUG_LEVEL_INFO, DEBUG_LEVEL_WARN, DEBUG_LEVEL_ERROR, @@ -79,9 +80,9 @@ void printBacktrace(void); sizeof(s) > 21 && (s)[sizeof(s)-22] == DIRECTORY_SEPARATOR ? (s) + sizeof(s) - 21 : (s)) #define DEBUG_PRINT(level, fmt, ...) do { \ - fprintf(stdout, "%s%12" PRId64 "%20s:%-4u | %-30s | " fmt "\n", \ + fprintf(stderr, "%s%12" PRId64 "%20s:%-4u | %-30s | " fmt "%s\n", \ debug_lookup[level], microtime(), STRIPPATH(__FILE__), \ - __LINE__, __FUNCTION__, ##__VA_ARGS__); \ + __LINE__, __FUNCTION__, ##__VA_ARGS__, debug_lookup[DEBUG_LEVEL_NONE]); \ } while (0) #define DEBUG_BREAK() DEBUG_PRINT(DEBUG_LEVEL_INFO, "================================================================================") diff --git a/common/src/platform/linux/debug.c b/common/src/platform/linux/debug.c index 310d46d8..62e0e0d5 100644 --- a/common/src/platform/linux/debug.c +++ b/common/src/platform/linux/debug.c @@ -34,6 +34,7 @@ void debug_init(void) { static const char * colorLookup[] = { + COLOR_RESET , // DEBUG_LEVEL_NONE COLOR_RESET "[I] ", // DEBUG_LEVEL_INFO COLOR_YELLOW "[W] ", // DEBUG_LEVEL_WARN COLOR_RED "[E] ", // DEBUG_LEVEL_ERROR @@ -43,6 +44,7 @@ void debug_init(void) static const char * plainLookup[] = { + "" , // DEBUG_LEVEL_NONE "[I] ", // DEBUG_LEVEL_INFO "[W] ", // DEBUG_LEVEL_WARN "[E] ", // DEBUG_LEVEL_ERROR @@ -50,5 +52,5 @@ void debug_init(void) "[!] " // DEBUG_LEVEL_FATAL }; - debug_lookup = (isatty(0) == 1) ? colorLookup : plainLookup; + debug_lookup = (isatty(STDERR_FILENO) == 1) ? colorLookup : plainLookup; } diff --git a/common/src/platform/windows/debug.c b/common/src/platform/windows/debug.c index 82eea38b..872bada2 100644 --- a/common/src/platform/windows/debug.c +++ b/common/src/platform/windows/debug.c @@ -26,6 +26,7 @@ void debug_init(void) { static const char * plainLookup[] = { + "" , // DEBUG_LEVEL_NONE "[I] ", // DEBUG_LEVEL_INFO "[W] ", // DEBUG_LEVEL_WARN "[E] ", // DEBUG_LEVEL_ERROR