mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-12-22 02:50:49 +01:00
NimBLELog allow custom log level colors.
This commit is contained in:
parent
6ee5174ba0
commit
9a1ae677b8
2 changed files with 214 additions and 9 deletions
113
Kconfig
113
Kconfig
|
@ -26,6 +26,113 @@ config NIMBLE_CPP_LOG_LEVEL
|
|||
default 3 if NIMBLE_CPP_LOG_LEVEL_INFO
|
||||
default 4 if NIMBLE_CPP_LOG_LEVEL_DEBUG
|
||||
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR
|
||||
bool "Enable log color override."
|
||||
default "n"
|
||||
help
|
||||
Enabling this option will allow NimBLE log levels to have
|
||||
specific colors assigned.
|
||||
|
||||
menu "NIMBLE Log Override Colors"
|
||||
depends on NIMBLE_CPP_LOG_OVERRIDE_COLOR
|
||||
|
||||
choice NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR
|
||||
prompt "NimBLE CPP log override color Error"
|
||||
default NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_NONE
|
||||
help
|
||||
Select NimBLE CPP log override error color.
|
||||
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_NONE
|
||||
bool "None"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_BLACK
|
||||
bool "Black"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_RED
|
||||
bool "Red"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_GREEN
|
||||
bool "Green"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_YELLOW
|
||||
bool "Yellow"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_BLUE
|
||||
bool "Blue"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_PURPLE
|
||||
bool "Purple"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_CYAN
|
||||
bool "Cyan"
|
||||
endchoice #NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR
|
||||
|
||||
choice NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN
|
||||
prompt "NimBLE CPP log override color Warning"
|
||||
default NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_NONE
|
||||
help
|
||||
Select NimBLE CPP log override warning color.
|
||||
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_NONE
|
||||
bool "None"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_BLACK
|
||||
bool "Black"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_RED
|
||||
bool "Red"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_GREEN
|
||||
bool "Green"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_YELLOW
|
||||
bool "Yellow"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_BLUE
|
||||
bool "Blue"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_PURPLE
|
||||
bool "Purple"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_CYAN
|
||||
bool "Cyan"
|
||||
endchoice #NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN
|
||||
|
||||
choice NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO
|
||||
prompt "NimBLE CPP log override color Info"
|
||||
default NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_NONE
|
||||
help
|
||||
Select NimBLE CPP log override info color.
|
||||
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_NONE
|
||||
bool "None"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_BLACK
|
||||
bool "Black"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_RED
|
||||
bool "Red"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_GREEN
|
||||
bool "Green"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_YELLOW
|
||||
bool "Yellow"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_BLUE
|
||||
bool "Blue"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_PURPLE
|
||||
bool "Purple"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_CYAN
|
||||
bool "Cyan"
|
||||
endchoice #NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO
|
||||
|
||||
choice NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG
|
||||
prompt "NimBLE CPP log override color Debug"
|
||||
default NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_NONE
|
||||
help
|
||||
Select NimBLE CPP log override debug color.
|
||||
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_NONE
|
||||
bool "None"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_BLACK
|
||||
bool "Black"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_RED
|
||||
bool "Red"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_GREEN
|
||||
bool "Green"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_YELLOW
|
||||
bool "Yellow"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_BLUE
|
||||
bool "Blue"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_PURPLE
|
||||
bool "Purple"
|
||||
config NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_CYAN
|
||||
bool "Cyan"
|
||||
endchoice #NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG
|
||||
endmenu
|
||||
|
||||
config NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT
|
||||
bool "Show NimBLE return codes as text in debug log."
|
||||
default "n"
|
||||
|
@ -77,12 +184,12 @@ config NIMBLE_CPP_DEBUG_ASSERT_ENABLED
|
|||
This will use approximately 1kB of flash memory.
|
||||
|
||||
config NIMBLE_CPP_FREERTOS_TASK_BLOCK_BIT
|
||||
int "FreeRTOS task block bit"
|
||||
int "FreeRTOS task block bit."
|
||||
default 31
|
||||
help
|
||||
Configure the bit to set in the task notification value when a task is blocked waiting for an event.
|
||||
This should be set to a bit that is not used by other notifications in the system.
|
||||
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
|
@ -130,4 +237,4 @@ if IDF_TARGET_ESP32P4
|
|||
endchoice
|
||||
endif
|
||||
|
||||
endmenu
|
||||
endmenu
|
110
src/NimBLELog.h
110
src/NimBLELog.h
|
@ -28,11 +28,109 @@
|
|||
# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
|
||||
# endif
|
||||
|
||||
# define NIMBLE_CPP_LOG_PRINT(level, tag, format, ...) \
|
||||
do { \
|
||||
if (CONFIG_NIMBLE_CPP_LOG_LEVEL >= level) ESP_LOG_LEVEL_LOCAL(level, tag, format, ##__VA_ARGS__); \
|
||||
# if defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR)
|
||||
# if CONFIG_LOG_COLORS
|
||||
# if defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_BLACK)
|
||||
# define NIMBLE_CPP_LOG_COLOR_D LOG_COLOR(LOG_COLOR_BLACK)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_RED)
|
||||
# define NIMBLE_CPP_LOG_COLOR_D LOG_COLOR(LOG_COLOR_RED)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_GREEN)
|
||||
# define NIMBLE_CPP_LOG_COLOR_D LOG_COLOR(LOG_COLOR_GREEN)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_YELLOW)
|
||||
# define NIMBLE_CPP_LOG_COLOR_D LOG_COLOR(LOG_COLOR_BROWN)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_BLUE)
|
||||
# define NIMBLE_CPP_LOG_COLOR_D LOG_COLOR(LOG_COLOR_BLUE)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_PURPLE)
|
||||
# define NIMBLE_CPP_LOG_COLOR_D LOG_COLOR(LOG_COLOR_PURPLE)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_DEBUG_CYAN)
|
||||
# define NIMBLE_CPP_LOG_COLOR_D LOG_COLOR(LOG_COLOR_CYAN)
|
||||
# else
|
||||
# define NIMBLE_CPP_LOG_COLOR_D
|
||||
# endif
|
||||
|
||||
# if defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_BLACK)
|
||||
# define NIMBLE_CPP_LOG_COLOR_I LOG_COLOR(LOG_COLOR_BLACK)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_RED)
|
||||
# define NIMBLE_CPP_LOG_COLOR_I LOG_COLOR(LOG_COLOR_RED)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_GREEN)
|
||||
# define NIMBLE_CPP_LOG_COLOR_I LOG_COLOR(LOG_COLOR_GREEN)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_YELLOW)
|
||||
# define NIMBLE_CPP_LOG_COLOR_I LOG_COLOR(LOG_COLOR_BROWN)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_BLUE)
|
||||
# define NIMBLE_CPP_LOG_COLOR_I LOG_COLOR(LOG_COLOR_BLUE)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_PURPLE)
|
||||
# define NIMBLE_CPP_LOG_COLOR_I LOG_COLOR(LOG_COLOR_PURPLE)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_INFO_CYAN)
|
||||
# define NIMBLE_CPP_LOG_COLOR_I LOG_COLOR(LOG_COLOR_CYAN)
|
||||
# else
|
||||
# define NIMBLE_CPP_LOG_COLOR_I
|
||||
# endif
|
||||
|
||||
# if defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_BLACK)
|
||||
# define NIMBLE_CPP_LOG_COLOR_W LOG_COLOR(LOG_COLOR_BLACK)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_RED)
|
||||
# define NIMBLE_CPP_LOG_COLOR_W LOG_COLOR(LOG_COLOR_RED)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_GREEN)
|
||||
# define NIMBLE_CPP_LOG_COLOR_W LOG_COLOR(LOG_COLOR_GREEN)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_YELLOW)
|
||||
# define NIMBLE_CPP_LOG_COLOR_W LOG_COLOR(LOG_COLOR_BROWN)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_BLUE)
|
||||
# define NIMBLE_CPP_LOG_COLOR_W LOG_COLOR(LOG_COLOR_BLUE)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_PURPLE)
|
||||
# define NIMBLE_CPP_LOG_COLOR_W LOG_COLOR(LOG_COLOR_PURPLE)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_WARN_CYAN)
|
||||
# define NIMBLE_CPP_LOG_COLOR_W LOG_COLOR(LOG_COLOR_CYAN)
|
||||
# else
|
||||
# define NIMBLE_CPP_LOG_COLOR_W
|
||||
# endif
|
||||
|
||||
# if defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_BLACK)
|
||||
# define NIMBLE_CPP_LOG_COLOR_E LOG_COLOR(LOG_COLOR_BLACK)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_RED)
|
||||
# define NIMBLE_CPP_LOG_COLOR_E LOG_COLOR(LOG_COLOR_RED)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_GREEN)
|
||||
# define NIMBLE_CPP_LOG_COLOR_E LOG_COLOR(LOG_COLOR_GREEN)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_YELLOW)
|
||||
# define NIMBLE_CPP_LOG_COLOR_E LOG_COLOR(LOG_COLOR_BROWN)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_BLUE)
|
||||
# define NIMBLE_CPP_LOG_COLOR_E LOG_COLOR(LOG_COLOR_BLUE)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_PURPLE)
|
||||
# define NIMBLE_CPP_LOG_COLOR_E LOG_COLOR(LOG_COLOR_PURPLE)
|
||||
# elif defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR_ERR_CYAN)
|
||||
# define NIMBLE_CPP_LOG_COLOR_E LOG_COLOR(LOG_COLOR_CYAN)
|
||||
# else
|
||||
# define NIMBLE_CPP_LOG_COLOR_E
|
||||
# endif
|
||||
# else //CONFIG_LOG_COLORS
|
||||
# define NIMBLE_CPP_LOG_COLOR_D
|
||||
# define NIMBLE_CPP_LOG_COLOR_I
|
||||
# define NIMBLE_CPP_LOG_COLOR_W
|
||||
# define NIMBLE_CPP_LOG_COLOR_E
|
||||
# endif //CONFIG_LOG_COLORS
|
||||
|
||||
# define NIMBLE_CPP_LOG_FORMAT(letter, format) NIMBLE_CPP_LOG_COLOR_##letter #letter " (%lu) %s: " format LOG_RESET_COLOR "\n"
|
||||
|
||||
# define NIMBLE_CPP_LOG_LEVEL_LOCAL(level, tag, format, ...) \
|
||||
do { \
|
||||
if (level==ESP_LOG_ERROR) { esp_log_write(ESP_LOG_ERROR, tag, NIMBLE_CPP_LOG_FORMAT(E, format), esp_log_timestamp(), tag __VA_OPT__(,) __VA_ARGS__); } \
|
||||
else if (level==ESP_LOG_WARN) { esp_log_write(ESP_LOG_WARN, tag, NIMBLE_CPP_LOG_FORMAT(W, format), esp_log_timestamp(), tag __VA_OPT__(,) __VA_ARGS__); } \
|
||||
else if (level==ESP_LOG_INFO) { esp_log_write(ESP_LOG_INFO, tag, NIMBLE_CPP_LOG_FORMAT(I, format), esp_log_timestamp(), tag __VA_OPT__(,) __VA_ARGS__); } \
|
||||
else { esp_log_write(ESP_LOG_DEBUG, tag, NIMBLE_CPP_LOG_FORMAT(D, format), esp_log_timestamp(), tag __VA_OPT__(,) __VA_ARGS__); } \
|
||||
} while(0)
|
||||
|
||||
# define NIMBLE_CPP_LOG_PRINT(level, tag, format, ...) \
|
||||
do { \
|
||||
if (CONFIG_NIMBLE_CPP_LOG_LEVEL >= level) NIMBLE_CPP_LOG_LEVEL_LOCAL(level, tag, format, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
# else
|
||||
# define NIMBLE_CPP_LOG_PRINT(level, tag, format, ...) \
|
||||
do { \
|
||||
if (CONFIG_NIMBLE_CPP_LOG_LEVEL >= level) ESP_LOG_LEVEL_LOCAL(level, tag, format, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
# endif /* CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR */
|
||||
|
||||
# define NIMBLE_LOGD(tag, format, ...) NIMBLE_CPP_LOG_PRINT(ESP_LOG_DEBUG, tag, format, ##__VA_ARGS__)
|
||||
# define NIMBLE_LOGI(tag, format, ...) NIMBLE_CPP_LOG_PRINT(ESP_LOG_INFO, tag, format, ##__VA_ARGS__)
|
||||
# define NIMBLE_LOGW(tag, format, ...) NIMBLE_CPP_LOG_PRINT(ESP_LOG_WARN, tag, format, ##__VA_ARGS__)
|
||||
|
@ -73,6 +171,6 @@
|
|||
# define NIMBLE_LOGE(tag, format, ...) (void)tag
|
||||
# endif
|
||||
|
||||
# endif /* CONFIG_NIMBLE_CPP_IDF */
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* NIMBLE_CPP_LOG_H_ */
|
||||
# endif /* CONFIG_NIMBLE_CPP_IDF */
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
#endif /* NIMBLE_CPP_LOG_H_ */
|
Loading…
Reference in a new issue