Indicate the log level in the serial console

This commit is contained in:
apio 2022-11-30 17:26:33 +01:00
parent 985d45ddfb
commit 3f40ccd703

View File

@ -14,11 +14,17 @@ static constexpr u32 WHITE = 0xffffffff;
static constexpr u32 YELLOW = 0xffffff00;
static constexpr u32 RED = 0xffff0000;
static Result<void> log_serial(LogLevel, const char* format, va_list origin)
static char log_level_letters[] = {'D', 'I', 'W', 'E'}; // D for debug, I for info, W for warning, E for error
static const char* ansi_color_codes_per_log_level[] = {"37", "37", "33", "31"}; // 37 is white, 33 yellow, 31 red
static Result<void> log_serial(LogLevel level, const char* format, va_list origin)
{
va_list ap;
va_copy(ap, origin);
TRY(Serial::printf("\x1b[%sm%c\x1b[0m ", ansi_color_codes_per_log_level[(int)level],
log_level_letters[(int)level]));
TRY(Serial::printf("[%6zu.%.6zu] ", Timer::ticks(), Timer::ticks_us() - (Timer::ticks() * 1000000)));
TRY(cstyle_format(