From 61e5958eff1ec7dd7cf8cc4541d444b0a62da5df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 28 Jun 2024 17:34:45 +0200 Subject: [PATCH] log: formatting: Add configuration for blue DBG log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's usual to show debug logs as blue. Showing dbg and info with different colors are good, but it's preferable to keep info logs with default color. Signed-off-by: Félix Piédallu --- subsys/logging/Kconfig.formatting | 3 +++ subsys/logging/log_output.c | 3 ++- tests/subsys/logging/log_output/prj.conf | 1 + tests/subsys/logging/log_output/src/log_output_test.c | 3 ++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/subsys/logging/Kconfig.formatting b/subsys/logging/Kconfig.formatting index 0723b7676aa..7c1e29782a2 100644 --- a/subsys/logging/Kconfig.formatting +++ b/subsys/logging/Kconfig.formatting @@ -145,6 +145,9 @@ if LOG_BACKEND_SHOW_COLOR config LOG_INFO_COLOR_GREEN bool "Use green color for info level logs" +config LOG_DBG_COLOR_BLUE + bool "Use blue color for debug level logs" + endif # LOG_BACKEND_SHOW_COLOR config LOG_TAG_MAX_LEN diff --git a/subsys/logging/log_output.c b/subsys/logging/log_output.c index cd8e898a354..3add3835a06 100644 --- a/subsys/logging/log_output.c +++ b/subsys/logging/log_output.c @@ -19,6 +19,7 @@ #define LOG_COLOR_CODE_RED "\x1B[1;31m" #define LOG_COLOR_CODE_GREEN "\x1B[1;32m" #define LOG_COLOR_CODE_YELLOW "\x1B[1;33m" +#define LOG_COLOR_CODE_BLUE "\x1B[1;34m" #define HEXDUMP_BYTES_IN_LINE 16 @@ -41,7 +42,7 @@ static const char *const colors[] = { LOG_COLOR_CODE_RED, /* err */ LOG_COLOR_CODE_YELLOW, /* warn */ IS_ENABLED(CONFIG_LOG_INFO_COLOR_GREEN) ? LOG_COLOR_CODE_GREEN : NULL, /* info */ - NULL /* dbg */ + IS_ENABLED(CONFIG_LOG_DBG_COLOR_BLUE) ? LOG_COLOR_CODE_BLUE : NULL, /* dbg */ }; static uint32_t freq; diff --git a/tests/subsys/logging/log_output/prj.conf b/tests/subsys/logging/log_output/prj.conf index 1d715c5167f..ca82305d6f0 100644 --- a/tests/subsys/logging/log_output/prj.conf +++ b/tests/subsys/logging/log_output/prj.conf @@ -4,3 +4,4 @@ CONFIG_LOG=y CONFIG_LOG_OUTPUT=y CONFIG_LOG_PRINTK=n CONFIG_ZTEST_STACK_SIZE=1152 +CONFIG_LOG_DBG_COLOR_BLUE=y diff --git a/tests/subsys/logging/log_output/src/log_output_test.c b/tests/subsys/logging/log_output/src/log_output_test.c index 21ee039f6e2..fd59baaf6e0 100644 --- a/tests/subsys/logging/log_output/src/log_output_test.c +++ b/tests/subsys/logging/log_output/src/log_output_test.c @@ -192,13 +192,14 @@ ZTEST(test_log_output, test_colors) #define LOG_COLOR_CODE_RED "\x1B[1;31m" #define LOG_COLOR_CODE_GREEN "\x1B[1;32m" #define LOG_COLOR_CODE_YELLOW "\x1B[1;33m" +#define LOG_COLOR_CODE_BLUE "\x1B[1;34m" char package[256]; static const char *const exp_strs[] = { LOG_COLOR_CODE_RED " " SNAME ": " TEST_STR LOG_COLOR_CODE_DEFAULT "\r\n", LOG_COLOR_CODE_YELLOW " " SNAME ": " TEST_STR LOG_COLOR_CODE_DEFAULT "\r\n", LOG_COLOR_CODE_DEFAULT " " SNAME ": " TEST_STR LOG_COLOR_CODE_DEFAULT "\r\n", - LOG_COLOR_CODE_DEFAULT " " SNAME ": " TEST_STR LOG_COLOR_CODE_DEFAULT "\r\n" + LOG_COLOR_CODE_BLUE " " SNAME ": " TEST_STR LOG_COLOR_CODE_DEFAULT "\r\n" }; uint8_t levels[] = {LOG_LEVEL_ERR, LOG_LEVEL_WRN, LOG_LEVEL_INF, LOG_LEVEL_DBG}; uint32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_COLORS;