mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-10 00:28:20 +00:00
[common] debug: output to stdout
and reset the the color at the end
This commit is contained in:
parent
e96a80dd20
commit
0acce0737f
@ -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, "================================================================================")
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user