Skip to content

Commit 80acb4b

Browse files
committed
[BREAKING] Refactor NimBLELog
* Cleanup style. * Remove NIMBLE_LOGC as it's use was limited to assertions. * Add delay after assert printf to allow time to display the message.
1 parent bc723ee commit 80acb4b

File tree

2 files changed

+32
-41
lines changed

2 files changed

+32
-41
lines changed

src/NimBLEDevice.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,8 @@ std::string NimBLEDevice::toString() {
12331233
* @param [in] line The line number where the assert occurred.
12341234
*/
12351235
void nimble_cpp_assert(const char* file, unsigned line) {
1236-
NIMBLE_LOGC("", "Assertion failed at %s:%u\n", file, line);
1236+
console_printf("Assertion failed at %s:%u\n", file, line);
1237+
ble_npl_time_delay(10);
12371238
abort();
12381239
}
12391240
# endif // CONFIG_NIMBLE_CPP_DEBUG_ASSERT_ENABLED

src/NimBLELog.h

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,75 +14,65 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
#ifndef MAIN_NIMBLELOG_H_
18-
#define MAIN_NIMBLELOG_H_
1917

20-
#include "nimconfig.h"
18+
#ifndef NIMBLE_CPP_LOG_H_
19+
#define NIMBLE_CPP_LOG_H_
2120

21+
#include "nimconfig.h"
2222
#if defined(CONFIG_BT_ENABLED)
2323

24-
#if defined(CONFIG_NIMBLE_CPP_IDF) // using esp-idf
24+
# if defined(CONFIG_NIMBLE_CPP_IDF)
2525
# include "esp_log.h"
2626
# include "console/console.h"
2727
# ifndef CONFIG_NIMBLE_CPP_LOG_LEVEL
28-
# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
28+
# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
2929
# endif
3030

31-
# define NIMBLE_CPP_LOG_PRINT(level, tag, format, ...) do { \
32-
if (CONFIG_NIMBLE_CPP_LOG_LEVEL >= level) \
33-
ESP_LOG_LEVEL_LOCAL(level, tag, format, ##__VA_ARGS__); \
34-
} while(0)
35-
36-
# define NIMBLE_LOGD(tag, format, ...) \
37-
NIMBLE_CPP_LOG_PRINT(ESP_LOG_DEBUG, tag, format, ##__VA_ARGS__)
38-
39-
# define NIMBLE_LOGI(tag, format, ...) \
40-
NIMBLE_CPP_LOG_PRINT(ESP_LOG_INFO, tag, format, ##__VA_ARGS__)
31+
# define NIMBLE_CPP_LOG_PRINT(level, tag, format, ...) \
32+
do { \
33+
if (CONFIG_NIMBLE_CPP_LOG_LEVEL >= level) ESP_LOG_LEVEL_LOCAL(level, tag, format, ##__VA_ARGS__); \
34+
} while (0)
4135

42-
# define NIMBLE_LOGW(tag, format, ...) \
43-
NIMBLE_CPP_LOG_PRINT(ESP_LOG_WARN, tag, format, ##__VA_ARGS__)
36+
# define NIMBLE_LOGD(tag, format, ...) NIMBLE_CPP_LOG_PRINT(ESP_LOG_DEBUG, tag, format, ##__VA_ARGS__)
37+
# define NIMBLE_LOGI(tag, format, ...) NIMBLE_CPP_LOG_PRINT(ESP_LOG_INFO, tag, format, ##__VA_ARGS__)
38+
# define NIMBLE_LOGW(tag, format, ...) NIMBLE_CPP_LOG_PRINT(ESP_LOG_WARN, tag, format, ##__VA_ARGS__)
39+
# define NIMBLE_LOGE(tag, format, ...) NIMBLE_CPP_LOG_PRINT(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__)
4440

45-
# define NIMBLE_LOGE(tag, format, ...) \
46-
NIMBLE_CPP_LOG_PRINT(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__)
47-
48-
#else // using Arduino
41+
# else
4942
# include "nimble/porting/nimble/include/syscfg/syscfg.h"
5043
# include "nimble/console/console.h"
5144
# ifndef CONFIG_NIMBLE_CPP_LOG_LEVEL
52-
# if defined(ARDUINO_ARCH_ESP32) && defined(CORE_DEBUG_LEVEL)
53-
# define CONFIG_NIMBLE_CPP_LOG_LEVEL CORE_DEBUG_LEVEL
54-
# else
55-
# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
56-
# endif
45+
# if defined(ARDUINO_ARCH_ESP32) && defined(CORE_DEBUG_LEVEL)
46+
# define CONFIG_NIMBLE_CPP_LOG_LEVEL CORE_DEBUG_LEVEL
47+
# else
48+
# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
49+
# endif
5750
# endif
5851

5952
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 4
60-
# define NIMBLE_LOGD( tag, format, ... ) console_printf("D %s: " format "\n", tag, ##__VA_ARGS__)
53+
# define NIMBLE_LOGD(tag, format, ...) console_printf("D %s: " format "\n", tag, ##__VA_ARGS__)
6154
# else
62-
# define NIMBLE_LOGD( tag, format, ... ) (void)tag
55+
# define NIMBLE_LOGD(tag, format, ...) (void)tag
6356
# endif
6457

6558
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 3
66-
# define NIMBLE_LOGI( tag, format, ... ) console_printf("I %s: " format "\n", tag, ##__VA_ARGS__)
59+
# define NIMBLE_LOGI(tag, format, ...) console_printf("I %s: " format "\n", tag, ##__VA_ARGS__)
6760
# else
68-
# define NIMBLE_LOGI( tag, format, ... ) (void)tag
61+
# define NIMBLE_LOGI(tag, format, ...) (void)tag
6962
# endif
7063

7164
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 2
72-
# define NIMBLE_LOGW( tag, format, ... ) console_printf("W %s: " format "\n", tag, ##__VA_ARGS__)
65+
# define NIMBLE_LOGW(tag, format, ...) console_printf("W %s: " format "\n", tag, ##__VA_ARGS__)
7366
# else
74-
# define NIMBLE_LOGW( tag, format, ... ) (void)tag
67+
# define NIMBLE_LOGW(tag, format, ...) (void)tag
7568
# endif
7669

7770
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 1
78-
# define NIMBLE_LOGE( tag, format, ... ) console_printf("E %s: " format "\n", tag, ##__VA_ARGS__)
71+
# define NIMBLE_LOGE(tag, format, ...) console_printf("E %s: " format "\n", tag, ##__VA_ARGS__)
7972
# else
80-
# define NIMBLE_LOGE( tag, format, ... ) (void)tag
73+
# define NIMBLE_LOGE(tag, format, ...) (void)tag
8174
# endif
8275

83-
#endif /* CONFIG_NIMBLE_CPP_IDF */
84-
85-
#define NIMBLE_LOGC( tag, format, ... ) console_printf("CRIT %s: " format "\n", tag, ##__VA_ARGS__)
86-
87-
#endif /* CONFIG_BT_ENABLED */
88-
#endif /* MAIN_NIMBLELOG_H_ */
76+
# endif /* CONFIG_NIMBLE_CPP_IDF */
77+
#endif /* CONFIG_BT_ENABLED */
78+
#endif /* NIMBLE_CPP_LOG_H_ */

0 commit comments

Comments
 (0)