console: Add ANSI escape sequences for highlighting
This patch adds ANSI escape sequences to highlight a log line based on its loglevel to the output of "interactive" consoles that are meant to be displayed on a terminal (e.g. UART). This should help make errors and warnings stand out better among the usual spew of debug messages. For users whose terminal or use case doesn't support these sequences for some reason (or who simply don't like them), they can be disabled with a Kconfig. While ANSI escape sequences can be used to add color, minicom (the presumably most common terminal emulator for UART endpoints?) doesn't support color output unless explicitly enabled (via -c command line flag), and other terminal emulators may have similar restrictions, so in an effort to make this as widely useful by default as possible I have chosen not to use color codes and implement this highlighting via bolding, underlining and inverting alone (which seem to go through in all cases). If desired, support for separate color highlighting could be added via Kconfig later. Signed-off-by: Julius Werner <jwerner@chromium.org> Change-Id: I868f4026918bc0e967c32e14bcf3ac05816415e8 Reviewed-on: https://review.coreboot.org/c/coreboot/+/61307 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Raul Rangel <rrangel@chromium.org>
This commit is contained in:
@@ -178,6 +178,29 @@ static const char bios_log_prefix[BIOS_LOG_PREFIX_MAX_LEVEL + 1][5] = {
|
||||
[BIOS_SPEW] = "SPEW ",
|
||||
};
|
||||
|
||||
/*
|
||||
* When printing to terminals supporting ANSI escape sequences, the following
|
||||
* escape sequences can be printed to highlight the respective log levels
|
||||
* according to the BIOS_LOG_ESCAPE_PATTERN printf() pattern. At the end of a
|
||||
* line, highlighting should be reset with the BIOS_LOG_ESCAPE_RESET seqence.
|
||||
*
|
||||
* The escape sequences used here set flags with the following meanings:
|
||||
* 1 = bold, 4 = underlined, 5 = blinking, 7 = inverted
|
||||
*/
|
||||
#define BIOS_LOG_ESCAPE_PATTERN "\x1b[%sm"
|
||||
#define BIOS_LOG_ESCAPE_RESET "\x1b[0m"
|
||||
static const char bios_log_escape[BIOS_LOG_PREFIX_MAX_LEVEL + 1][8] = {
|
||||
[BIOS_EMERG] = "1;4;5;7",
|
||||
[BIOS_ALERT] = "1;4;7",
|
||||
[BIOS_CRIT] = "1;7",
|
||||
[BIOS_ERR] = "7",
|
||||
[BIOS_WARNING] = "1;4",
|
||||
[BIOS_NOTICE] = "1",
|
||||
[BIOS_INFO] = "0",
|
||||
[BIOS_DEBUG] = "0",
|
||||
[BIOS_SPEW] = "0",
|
||||
};
|
||||
|
||||
#endif /* __ASSEMBLER__ */
|
||||
|
||||
#endif /* LOGLEVEL_H */
|
||||
|
Reference in New Issue
Block a user