mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-11-01 12:57:52 +00:00
Handle invalid Log::Level::Count
Add a case of `Log::Level::Count` to all switch statements that dispatch on `Log::Level`. The case simply asserts `false` and notes the invalid log level.
This commit is contained in:
parent
1af1c5c37b
commit
9ff23da255
2 changed files with 9 additions and 1 deletions
|
@ -6,6 +6,7 @@
|
|||
#include <array>
|
||||
#include <cstdio>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/common_funcs.h" // snprintf compatibility define
|
||||
#include "common/logging/backend.h"
|
||||
#include "common/logging/filter.h"
|
||||
|
@ -78,8 +79,10 @@ const char* GetLevelName(Level log_level) {
|
|||
LVL(Warning);
|
||||
LVL(Error);
|
||||
LVL(Critical);
|
||||
case Level::Count:
|
||||
ASSERT_MSG(false, "invalid log level");
|
||||
return "Unknown";
|
||||
}
|
||||
return "Unknown";
|
||||
#undef LVL
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "common/logging/log.h"
|
||||
#include "common/logging/text_formatter.h"
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/string_util.h"
|
||||
|
||||
|
@ -82,6 +83,8 @@ void PrintColoredMessage(const Entry& entry) {
|
|||
color = FOREGROUND_RED | FOREGROUND_INTENSITY; break;
|
||||
case Level::Critical: // Bright magenta
|
||||
color = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break;
|
||||
case Level::Count:
|
||||
ASSERT_MSG(false, "invalid log level"); break;
|
||||
}
|
||||
|
||||
SetConsoleTextAttribute(console_handle, color);
|
||||
|
@ -101,6 +104,8 @@ void PrintColoredMessage(const Entry& entry) {
|
|||
color = ESC "[1;31m"; break;
|
||||
case Level::Critical: // Bright magenta
|
||||
color = ESC "[1;35m"; break;
|
||||
case Level::Count:
|
||||
ASSERT_MSG(false, "invalid log level"); break;
|
||||
}
|
||||
|
||||
fputs(color, stderr);
|
||||
|
|
Loading…
Reference in a new issue