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 <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2015-12-08 12:17:31 +02:00 committed by Anas Nashif
commit 30e0e64407
2 changed files with 20 additions and 2 deletions

View file

@ -22,11 +22,23 @@
#include <stdio.h>
#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"); \

View file

@ -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