mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-12-22 19:10:46 +01:00
Add config option for log verbosity.
This commit is contained in:
parent
798726c05d
commit
ea02eb9452
5 changed files with 82 additions and 48 deletions
26
Kconfig
26
Kconfig
|
@ -1,5 +1,31 @@
|
|||
menu "ESP-NimBLE-CPP configuration"
|
||||
|
||||
choice NIMBLE_CPP_LOG_LEVEL
|
||||
prompt "NimBLE CPP log verbosity"
|
||||
default NIMBLE_CPP_LOG_LEVEL_NONE
|
||||
help
|
||||
Select NimBLE CPP log verbosity level.
|
||||
|
||||
config NIMBLE_CPP_LOG_LEVEL_NONE
|
||||
bool "No logs"
|
||||
config NIMBLE_CPP_LOG_LEVEL_ERROR
|
||||
bool "Error logs"
|
||||
config NIMBLE_CPP_LOG_LEVEL_WARNING
|
||||
bool "Warning logs"
|
||||
config NIMBLE_CPP_LOG_LEVEL_INFO
|
||||
bool "Info logs"
|
||||
config NIMBLE_CPP_LOG_LEVEL_DEBUG
|
||||
bool "Debug logs"
|
||||
endchoice #NIMBLE_CPP_LOG_LEVEL
|
||||
|
||||
config NIMBLE_CPP_LOG_LEVEL
|
||||
int
|
||||
default 0 if NIMBLE_CPP_LOG_LEVEL_NONE
|
||||
default 1 if NIMBLE_CPP_LOG_LEVEL_ERROR
|
||||
default 2 if NIMBLE_CPP_LOG_LEVEL_WARNING
|
||||
default 3 if NIMBLE_CPP_LOG_LEVEL_INFO
|
||||
default 4 if NIMBLE_CPP_LOG_LEVEL_DEBUG
|
||||
|
||||
config NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT
|
||||
bool "Show NimBLE return codes as text in debug log."
|
||||
default "n"
|
||||
|
|
|
@ -520,7 +520,7 @@ NimBLECharacteristicCallbacks* NimBLECharacteristic::getCallbacks() {
|
|||
* @param [in] length The length of the data in bytes.
|
||||
*/
|
||||
void NimBLECharacteristic::setValue(const uint8_t* data, size_t length) {
|
||||
#if CONFIG_NIMBLE_CPP_DEBUG_LEVEL >= 4
|
||||
#if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 4
|
||||
char* pHex = NimBLEUtils::buildHexData(nullptr, data, length);
|
||||
NIMBLE_LOGD(LOG_TAG, ">> setValue: length=%d, data=%s, characteristic UUID=%s", length, pHex, getUUID().toString().c_str());
|
||||
free(pHex);
|
||||
|
|
|
@ -13,59 +13,67 @@
|
|||
#if defined(CONFIG_BT_ENABLED)
|
||||
|
||||
#if defined(CONFIG_NIMBLE_CPP_IDF) // using esp-idf
|
||||
# include "esp_log.h"
|
||||
# ifndef CONFIG_NIMBLE_CPP_LOG_LEVEL
|
||||
# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
|
||||
# endif
|
||||
|
||||
#include "esp_log.h"
|
||||
# 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)
|
||||
|
||||
#define NIMBLE_LOGE(tag, format, ...) ESP_LOGE(tag, format, ##__VA_ARGS__)
|
||||
#define NIMBLE_LOGW(tag, format, ...) ESP_LOGW(tag, format, ##__VA_ARGS__)
|
||||
#define NIMBLE_LOGI(tag, format, ...) ESP_LOGI(tag, format, ##__VA_ARGS__)
|
||||
#define NIMBLE_LOGD(tag, format, ...) ESP_LOGD(tag, format, ##__VA_ARGS__)
|
||||
#define NIMBLE_LOGC(tag, format, ...) ESP_LOGE(tag, format, ##__VA_ARGS__)
|
||||
# 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__)
|
||||
|
||||
# define NIMBLE_LOGE(tag, format, ...) \
|
||||
NIMBLE_CPP_LOG_PRINT(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__)
|
||||
|
||||
# define NIMBLE_LOGC(tag, format, ...) \
|
||||
NIMBLE_CPP_LOG_PRINT(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__)
|
||||
|
||||
#else // using Arduino
|
||||
# include "nimble/porting/nimble/include/syscfg/syscfg.h"
|
||||
# include "nimble/console/console.h"
|
||||
# ifndef CONFIG_NIMBLE_CPP_LOG_LEVEL
|
||||
# if defined(ARDUINO_ARCH_ESP32) && defined(CORE_DEBUG_LEVEL)
|
||||
# define CONFIG_NIMBLE_CPP_LOG_LEVEL CORE_DEBUG_LEVEL
|
||||
# else
|
||||
# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
|
||||
# endif
|
||||
# endif
|
||||
|
||||
#include "nimble/porting/nimble/include/syscfg/syscfg.h"
|
||||
#include "nimble/console/console.h"
|
||||
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 4
|
||||
# define NIMBLE_LOGD( tag, format, ... ) console_printf("D %s: "#format"\n",tag,##__VA_ARGS__)
|
||||
# else
|
||||
# define NIMBLE_LOGD( tag, format, ... ) (void)tag
|
||||
# endif
|
||||
|
||||
// If Arduino is being used, strip out the colors and ignore log printing below ui setting.
|
||||
// Note: because CONFIG_LOG_DEFAULT_LEVEL is set at ERROR in Arduino we must use MODLOG_DFLT(ERROR
|
||||
// otherwise no messages will be printed above that level.
|
||||
|
||||
#ifndef CONFIG_NIMBLE_CPP_DEBUG_LEVEL
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(CORE_DEBUG_LEVEL)
|
||||
#define CONFIG_NIMBLE_CPP_DEBUG_LEVEL CORE_DEBUG_LEVEL
|
||||
#else
|
||||
#define CONFIG_NIMBLE_CPP_DEBUG_LEVEL 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CONFIG_NIMBLE_CPP_DEBUG_LEVEL >= 4
|
||||
#define NIMBLE_LOGD( tag, format, ... ) console_printf("D %s: "#format"\n",tag,##__VA_ARGS__)
|
||||
#else
|
||||
#define NIMBLE_LOGD( tag, format, ... ) (void)tag
|
||||
#endif
|
||||
|
||||
#if CONFIG_NIMBLE_CPP_DEBUG_LEVEL >= 3
|
||||
#define NIMBLE_LOGI( tag, format, ... ) console_printf("I %s: "#format"\n",tag,##__VA_ARGS__)
|
||||
#else
|
||||
#define NIMBLE_LOGI( tag, format, ... ) (void)tag
|
||||
#endif
|
||||
|
||||
#if CONFIG_NIMBLE_CPP_DEBUG_LEVEL >= 2
|
||||
#define NIMBLE_LOGW( tag, format, ... ) console_printf("W %s: "#format"\n",tag,##__VA_ARGS__)
|
||||
#else
|
||||
#define NIMBLE_LOGW( tag, format, ... ) (void)tag
|
||||
#endif
|
||||
|
||||
#if CONFIG_NIMBLE_CPP_DEBUG_LEVEL >= 1
|
||||
#define NIMBLE_LOGE( tag, format, ... ) console_printf("E %s: "#format"\n",tag,##__VA_ARGS__)
|
||||
#define NIMBLE_LOGC( tag, format, ... ) console_printf("CRIT %s: "#format"\n",tag,##__VA_ARGS__)
|
||||
#else
|
||||
#define NIMBLE_LOGE( tag, format, ... ) (void)tag
|
||||
#define NIMBLE_LOGC( tag, format, ... ) (void)tag
|
||||
#endif
|
||||
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 3
|
||||
# define NIMBLE_LOGI( tag, format, ... ) console_printf("I %s: "#format"\n",tag,##__VA_ARGS__)
|
||||
# else
|
||||
# define NIMBLE_LOGI( tag, format, ... ) (void)tag
|
||||
# endif
|
||||
|
||||
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 2
|
||||
# define NIMBLE_LOGW( tag, format, ... ) console_printf("W %s: "#format"\n",tag,##__VA_ARGS__)
|
||||
# else
|
||||
# define NIMBLE_LOGW( tag, format, ... ) (void)tag
|
||||
# endif
|
||||
|
||||
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 1
|
||||
# define NIMBLE_LOGE( tag, format, ... ) console_printf("E %s: "#format"\n",tag,##__VA_ARGS__)
|
||||
# define NIMBLE_LOGC( tag, format, ... ) console_printf("CRIT %s: "#format"\n",tag,##__VA_ARGS__)
|
||||
# else
|
||||
# define NIMBLE_LOGE( tag, format, ... ) (void)tag
|
||||
# define NIMBLE_LOGC( tag, format, ... ) (void)tag
|
||||
# endif
|
||||
|
||||
#endif /* CONFIG_NIMBLE_CPP_IDF */
|
||||
#endif /* CONFIG_BT_ENABLED */
|
||||
|
|
|
@ -181,7 +181,7 @@ void NimBLEServer::start() {
|
|||
abort();
|
||||
}
|
||||
|
||||
#if CONFIG_NIMBLE_CPP_DEBUG_LEVEL >= 4
|
||||
#if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 4
|
||||
ble_gatts_show_local();
|
||||
#endif
|
||||
/*** Future use ***
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
* Values: 0 = NONE, 1 = ERROR, 2 = WARNING, 3 = INFO, 4+ = DEBUG\n
|
||||
* Uses approx. 32kB of flash memory.
|
||||
*/
|
||||
#define CONFIG_NIMBLE_CPP_DEBUG_LEVEL 0
|
||||
#define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
|
||||
|
||||
/** @brief Un-comment to see NimBLE host return codes as text debug log messages.
|
||||
* Uses approx. 7kB of flash memory.
|
||||
|
|
Loading…
Reference in a new issue