From 30e0e64407f6a80d682508cd243dde10c1792a6d Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 8 Dec 2015 12:17:31 +0200 Subject: [PATCH] Bluetooth: Add color logging support Add basic color logging support. Error logs will be printed in red whereas warn() logs in yellow. The support is behind a Kconfig option in case someone needs to build the stack for a terminal that doesn't support the ANSI color codes. Change-Id: I080e32db68f87e81f1bb54aa4c634f7cd38f1e33 Signed-off-by: Johan Hedberg --- include/bluetooth/log.h | 16 ++++++++++++++-- net/bluetooth/Kconfig | 6 ++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/bluetooth/log.h b/include/bluetooth/log.h index 1c96529eb67..33ecf378fb0 100644 --- a/include/bluetooth/log.h +++ b/include/bluetooth/log.h @@ -22,11 +22,23 @@ #include +#if defined(CONFIG_BLUETOOTH_DEBUG_COLOR) +#define BT_COLOR_OFF "\x1B[0m" +#define BT_COLOR_RED "\x1B[0;31m" +#define BT_COLOR_YELLOW "\x1B[0;33m" +#else +#define BT_COLOR_OFF "" +#define BT_COLOR_RED "" +#define BT_COLOR_YELLOW "" +#endif + #if defined(CONFIG_BLUETOOTH_DEBUG) #define BT_DBG(fmt, ...) printf("bt: %s (%p): " fmt "\n", __func__, \ sys_thread_self_get(), ##__VA_ARGS__) -#define BT_ERR(fmt, ...) printf("bt: %s: " fmt "\n", __func__, ##__VA_ARGS__) -#define BT_WARN(fmt, ...) printf("bt: %s: " fmt "\n", __func__, ##__VA_ARGS__) +#define BT_ERR(fmt, ...) printf("bt: %s: %s" fmt "%s\n", __func__, \ + BT_COLOR_RED, ##__VA_ARGS__, BT_COLOR_OFF) +#define BT_WARN(fmt, ...) printf("bt: %s: %s" fmt "%s\n", __func__, \ + BT_COLOR_YELLOW, ##__VA_ARGS__, BT_COLOR_OFF) #define BT_INFO(fmt, ...) printf("bt: " fmt "\n", ##__VA_ARGS__) #define BT_ASSERT(cond) if (!(cond)) { \ BT_ERR("bt: assert: '" #cond "' failed"); \ diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig index d5ef8100200..42de1a6e361 100644 --- a/net/bluetooth/Kconfig +++ b/net/bluetooth/Kconfig @@ -172,6 +172,12 @@ config BLUETOOTH_DEBUG serial console. if BLUETOOTH_DEBUG +config BLUETOOTH_DEBUG_COLOR + bool "Use colored logs" + default y + help + Use color in the logs. This requires an ANSI capable terminal. + config BLUETOOTH_DEBUG_HCI_CORE bool "Bluetooth HCI core debug" default n