logging: fix color being shown even if disabled

If CONFIG_LOG_BACKEND_SHOW_COLOR is disabled, error and warning
lines are still being outputted with color, which is contrary to
what the Kconfig says. So change the color settings for error
and warning lines to no color if this Kconfig is disabled.

The log_output test is also amended to account for this.
Though the test is not skipped as no color is still some colors
(... well... maybe).

Fixes #77150

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2024-08-16 16:46:46 -07:00 committed by Alberto Escolar
commit 060538ee28
4 changed files with 30 additions and 7 deletions

View file

@ -0,0 +1,12 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# Copyright (c) 2024 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
config LOG_INFO_COLOR_GREEN
default y if LOG_BACKEND_SHOW_COLOR
config LOG_DBG_COLOR_BLUE
default y if LOG_BACKEND_SHOW_COLOR
source "Kconfig.zephyr"

View file

@ -4,4 +4,3 @@ CONFIG_LOG=y
CONFIG_LOG_OUTPUT=y
CONFIG_LOG_PRINTK=n
CONFIG_ZTEST_STACK_SIZE=1152
CONFIG_LOG_DBG_COLOR_BLUE=y

View file

@ -194,12 +194,24 @@ ZTEST(test_log_output, test_colors)
#define LOG_COLOR_CODE_YELLOW "\x1B[1;33m"
#define LOG_COLOR_CODE_BLUE "\x1B[1;34m"
#ifdef CONFIG_LOG_BACKEND_SHOW_COLOR
#define LOG_COLOR_ERR LOG_COLOR_CODE_RED
#define LOG_COLOR_WRN LOG_COLOR_CODE_YELLOW
#define LOG_COLOR_INF LOG_COLOR_CODE_GREEN
#define LOG_COLOR_DBG LOG_COLOR_CODE_BLUE
#else
#define LOG_COLOR_ERR LOG_COLOR_CODE_DEFAULT
#define LOG_COLOR_WRN LOG_COLOR_CODE_DEFAULT
#define LOG_COLOR_INF LOG_COLOR_CODE_DEFAULT
#define LOG_COLOR_DBG LOG_COLOR_CODE_DEFAULT
#endif /* CONFIG_LOG_BACKEND_SHOW_COLOR */
char package[256];
static const char *const exp_strs[] = {
LOG_COLOR_CODE_RED "<err> " SNAME ": " TEST_STR LOG_COLOR_CODE_DEFAULT "\r\n",
LOG_COLOR_CODE_YELLOW "<wrn> " SNAME ": " TEST_STR LOG_COLOR_CODE_DEFAULT "\r\n",
LOG_COLOR_CODE_DEFAULT "<inf> " SNAME ": " TEST_STR LOG_COLOR_CODE_DEFAULT "\r\n",
LOG_COLOR_CODE_BLUE "<dbg> " SNAME ": " TEST_STR LOG_COLOR_CODE_DEFAULT "\r\n"
LOG_COLOR_ERR "<err> " SNAME ": " TEST_STR LOG_COLOR_CODE_DEFAULT "\r\n",
LOG_COLOR_WRN "<wrn> " SNAME ": " TEST_STR LOG_COLOR_CODE_DEFAULT "\r\n",
LOG_COLOR_INF "<inf> " SNAME ": " TEST_STR LOG_COLOR_CODE_DEFAULT "\r\n",
LOG_COLOR_DBG "<dbg> " 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;