From 3f40ccd7037bca1611af8a59027c2239058c5f23 Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 30 Nov 2022 17:26:33 +0100 Subject: [PATCH] Indicate the log level in the serial console --- kernel/src/Log.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/src/Log.cpp b/kernel/src/Log.cpp index 63519d43..67704922 100644 --- a/kernel/src/Log.cpp +++ b/kernel/src/Log.cpp @@ -14,11 +14,17 @@ static constexpr u32 WHITE = 0xffffffff; static constexpr u32 YELLOW = 0xffffff00; static constexpr u32 RED = 0xffff0000; -static Result 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 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(