Skip to content

Commit 7a35ad3

Browse files
committed
Add Log level macro.
This allows for setting the log level of the library separately from the arduino core log level.
1 parent e36381e commit 7a35ad3

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

src/NimBLECharacteristic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ NimBLECharacteristicCallbacks* NimBLECharacteristic::getCallbacks() {
516516
* @param [in] length The length of the data in bytes.
517517
*/
518518
void NimBLECharacteristic::setValue(const uint8_t* data, size_t length) {
519-
#if CONFIG_LOG_DEFAULT_LEVEL > 3 || (ARDUINO_ARCH_ESP32 && CORE_DEBUG_LEVEL >= 4)
519+
#if CONFIG_NIMBLE_CPP_DEBUG_LEVEL >= 4
520520
char* pHex = NimBLEUtils::buildHexData(nullptr, data, length);
521521
NIMBLE_LOGD(LOG_TAG, ">> setValue: length=%d, data=%s, characteristic UUID=%s", length, pHex, getUUID().toString().c_str());
522522
free(pHex);

src/NimBLELog.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef MAIN_NIMBLELOG_H_
99
#define MAIN_NIMBLELOG_H_
1010

11-
#include "sdkconfig.h"
11+
#include "nimconfig.h"
1212

1313
#if defined(CONFIG_BT_ENABLED)
1414

@@ -20,29 +20,33 @@
2020
// Note: because CONFIG_LOG_DEFAULT_LEVEL is set at ERROR in Arduino we must use MODLOG_DFLT(ERROR
2121
// otherwise no messages will be printed above that level.
2222

23-
#ifndef CORE_DEBUG_LEVEL
24-
#define CORE_DEBUG_LEVEL CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL
23+
#ifndef CONFIG_NIMBLE_CPP_DEBUG_LEVEL
24+
#ifdef CORE_DEBUG_LEVEL
25+
#define CONFIG_NIMBLE_CPP_DEBUG_LEVEL CORE_DEBUG_LEVEL
26+
#else
27+
#define CONFIG_NIMBLE_CPP_DEBUG_LEVEL 0
28+
#endif
2529
#endif
2630

27-
#if CORE_DEBUG_LEVEL >= 4
31+
#if CONFIG_NIMBLE_CPP_DEBUG_LEVEL >= 4
2832
#define NIMBLE_LOGD( tag, format, ... ) MODLOG_DFLT(ERROR, "D %s: "#format"\n",tag,##__VA_ARGS__)
2933
#else
3034
#define NIMBLE_LOGD( tag, format, ... ) (void)tag
3135
#endif
3236

33-
#if CORE_DEBUG_LEVEL >= 3
37+
#if CONFIG_NIMBLE_CPP_DEBUG_LEVEL >= 3
3438
#define NIMBLE_LOGI( tag, format, ... ) MODLOG_DFLT(ERROR, "I %s: "#format"\n",tag,##__VA_ARGS__)
3539
#else
3640
#define NIMBLE_LOGI( tag, format, ... ) (void)tag
3741
#endif
3842

39-
#if CORE_DEBUG_LEVEL >= 2
43+
#if CONFIG_NIMBLE_CPP_DEBUG_LEVEL >= 2
4044
#define NIMBLE_LOGW( tag, format, ... ) MODLOG_DFLT(ERROR, "W %s: "#format"\n",tag,##__VA_ARGS__)
4145
#else
4246
#define NIMBLE_LOGW( tag, format, ... ) (void)tag
4347
#endif
4448

45-
#if CORE_DEBUG_LEVEL >= 1
49+
#if CONFIG_NIMBLE_CPP_DEBUG_LEVEL >= 1
4650
#define NIMBLE_LOGE( tag, format, ... ) MODLOG_DFLT(ERROR, "E %s: "#format"\n",tag,##__VA_ARGS__)
4751
#else
4852
#define NIMBLE_LOGE( tag, format, ... ) (void)tag

src/NimBLEServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void NimBLEServer::start() {
181181
abort();
182182
}
183183

184-
#if CONFIG_LOG_DEFAULT_LEVEL > 3 || (ARDUINO_ARCH_ESP32 && CORE_DEBUG_LEVEL >= 4)
184+
#if CONFIG_NIMBLE_CPP_DEBUG_LEVEL >= 4
185185
ble_gatts_show_local();
186186
#endif
187187
/*** Future use ***

src/nimconfig.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
*/
2222
// #define CONFIG_BT_NIMBLE_DEBUG
2323

24+
/** @brief Un-comment to set the debug log messages level from the NimBLE CPP Wrapper.\n
25+
* Values: 0 = NONE, 1 = ERROR, 2 = WARNING, 3 = INFO, 4+ = DEBUG\n
26+
* Uses approx. 32kB of flash memory.
27+
*/
28+
// #define CONFIG_NIMBLE_CPP_DEBUG_LEVEL 0
29+
2430
/** @brief Un-comment to see NimBLE host return codes as text debug log messages.
2531
* Uses approx. 7kB of flash memory.
2632
*/

0 commit comments

Comments
 (0)