Improve the console error logging appearance

This makes secondary information less visually prominent
to improve overall readability.

Various loggers were also tweaked for consistency.
This commit is contained in:
Hugo Locurcio
2020-01-18 23:26:28 +01:00
parent d4a222cd9d
commit 580b8cc012
4 changed files with 59 additions and 82 deletions

View File

@ -85,7 +85,6 @@ void WindowsTerminalLogger::log_error(const char *p_function, const char *p_file
CONSOLE_SCREEN_BUFFER_INFO sbi; //original
GetConsoleScreenBufferInfo(hCon, &sbi);
WORD current_fg = sbi.wAttributes & (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
WORD current_bg = sbi.wAttributes & (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
uint32_t basecol = 0;
@ -98,53 +97,34 @@ void WindowsTerminalLogger::log_error(const char *p_function, const char *p_file
basecol |= current_bg;
SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY);
switch (p_type) {
case ERR_ERROR: logf("ERROR:"); break;
case ERR_WARNING: logf("WARNING:"); break;
case ERR_SCRIPT: logf("SCRIPT ERROR:"); break;
case ERR_SHADER: logf("SHADER ERROR:"); break;
}
SetConsoleTextAttribute(hCon, basecol);
if (p_rationale && p_rationale[0]) {
SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY);
switch (p_type) {
case ERR_ERROR: logf("ERROR: "); break;
case ERR_WARNING: logf("WARNING: "); break;
case ERR_SCRIPT: logf("SCRIPT ERROR: "); break;
case ERR_SHADER: logf("SHADER ERROR: "); break;
}
SetConsoleTextAttribute(hCon, current_fg | current_bg | FOREGROUND_INTENSITY);
logf("%s\n", p_rationale);
SetConsoleTextAttribute(hCon, basecol);
switch (p_type) {
case ERR_ERROR: logf(" At: "); break;
case ERR_WARNING: logf(" At: "); break;
case ERR_SCRIPT: logf(" At: "); break;
case ERR_SHADER: logf(" At: "); break;
}
SetConsoleTextAttribute(hCon, current_fg | current_bg);
logf("%s:%i\n", p_file, p_line);
logf(" %s\n", p_rationale);
} else {
logf(" %s\n", p_code);
}
SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY);
switch (p_type) {
case ERR_ERROR: logf("ERROR: %s: ", p_function); break;
case ERR_WARNING: logf("WARNING: %s: ", p_function); break;
case ERR_SCRIPT: logf("SCRIPT ERROR: %s: ", p_function); break;
case ERR_SHADER: logf("SCRIPT ERROR: %s: ", p_function); break;
}
// `FOREGROUND_INTENSITY` alone results in gray text.
SetConsoleTextAttribute(hCon, FOREGROUND_INTENSITY);
switch (p_type) {
case ERR_ERROR: logf(" at: "); break;
case ERR_WARNING: logf(" at: "); break;
case ERR_SCRIPT: logf(" at: "); break;
case ERR_SHADER: logf(" at: "); break;
}
SetConsoleTextAttribute(hCon, current_fg | current_bg | FOREGROUND_INTENSITY);
logf("%s\n", p_code);
SetConsoleTextAttribute(hCon, basecol);
switch (p_type) {
case ERR_ERROR: logf(" At: "); break;
case ERR_WARNING: logf(" At: "); break;
case ERR_SCRIPT: logf(" At: "); break;
case ERR_SHADER: logf(" At: "); break;
}
SetConsoleTextAttribute(hCon, current_fg | current_bg);
logf("%s:%i\n", p_file, p_line);
if (p_rationale && p_rationale[0]) {
logf("(%s:%i)\n", p_file, p_line);
} else {
logf("%s (%s:%i)\n", p_function, p_file, p_line);
}
SetConsoleTextAttribute(hCon, sbi.wAttributes);