|
13 | 13 | #if defined(CONFIG_BT_ENABLED) |
14 | 14 |
|
15 | 15 | #if defined(CONFIG_NIMBLE_CPP_IDF) // using esp-idf |
| 16 | +# include "esp_log.h" |
| 17 | +# ifndef CONFIG_NIMBLE_CPP_LOG_LEVEL |
| 18 | +# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0 |
| 19 | +# endif |
16 | 20 |
|
17 | | -#include "esp_log.h" |
| 21 | +# define NIMBLE_CPP_LOG_PRINT(level, tag, format, ...) do { \ |
| 22 | + if (CONFIG_NIMBLE_CPP_LOG_LEVEL >= level) \ |
| 23 | + ESP_LOG_LEVEL_LOCAL(level, tag, format, ##__VA_ARGS__); \ |
| 24 | + } while(0) |
18 | 25 |
|
19 | | -#define NIMBLE_LOGE(tag, format, ...) ESP_LOGE(tag, format, ##__VA_ARGS__) |
20 | | -#define NIMBLE_LOGW(tag, format, ...) ESP_LOGW(tag, format, ##__VA_ARGS__) |
21 | | -#define NIMBLE_LOGI(tag, format, ...) ESP_LOGI(tag, format, ##__VA_ARGS__) |
22 | | -#define NIMBLE_LOGD(tag, format, ...) ESP_LOGD(tag, format, ##__VA_ARGS__) |
23 | | -#define NIMBLE_LOGC(tag, format, ...) ESP_LOGE(tag, format, ##__VA_ARGS__) |
| 26 | +# define NIMBLE_LOGD(tag, format, ...) \ |
| 27 | + NIMBLE_CPP_LOG_PRINT(ESP_LOG_DEBUG, tag, format, ##__VA_ARGS__) |
24 | 28 |
|
25 | | -#else // using Arduino |
26 | | - |
27 | | -#include "nimble/porting/nimble/include/syscfg/syscfg.h" |
28 | | -#include "nimble/console/console.h" |
29 | | - |
30 | | -// If Arduino is being used, strip out the colors and ignore log printing below ui setting. |
31 | | -// Note: because CONFIG_LOG_DEFAULT_LEVEL is set at ERROR in Arduino we must use MODLOG_DFLT(ERROR |
32 | | -// otherwise no messages will be printed above that level. |
33 | | - |
34 | | -#ifndef CONFIG_NIMBLE_CPP_DEBUG_LEVEL |
35 | | - #if defined(ARDUINO_ARCH_ESP32) && defined(CORE_DEBUG_LEVEL) |
36 | | - #define CONFIG_NIMBLE_CPP_DEBUG_LEVEL CORE_DEBUG_LEVEL |
37 | | - #else |
38 | | - #define CONFIG_NIMBLE_CPP_DEBUG_LEVEL 0 |
39 | | - #endif |
40 | | -#endif |
| 29 | +# define NIMBLE_LOGI(tag, format, ...) \ |
| 30 | + NIMBLE_CPP_LOG_PRINT(ESP_LOG_INFO, tag, format, ##__VA_ARGS__) |
41 | 31 |
|
42 | | -#if CONFIG_NIMBLE_CPP_DEBUG_LEVEL >= 4 |
43 | | -#define NIMBLE_LOGD( tag, format, ... ) console_printf("D %s: "#format"\n",tag,##__VA_ARGS__) |
44 | | -#else |
45 | | -#define NIMBLE_LOGD( tag, format, ... ) (void)tag |
46 | | -#endif |
| 32 | +# define NIMBLE_LOGW(tag, format, ...) \ |
| 33 | + NIMBLE_CPP_LOG_PRINT(ESP_LOG_WARN, tag, format, ##__VA_ARGS__) |
47 | 34 |
|
48 | | -#if CONFIG_NIMBLE_CPP_DEBUG_LEVEL >= 3 |
49 | | -#define NIMBLE_LOGI( tag, format, ... ) console_printf("I %s: "#format"\n",tag,##__VA_ARGS__) |
50 | | -#else |
51 | | -#define NIMBLE_LOGI( tag, format, ... ) (void)tag |
52 | | -#endif |
53 | | - |
54 | | -#if CONFIG_NIMBLE_CPP_DEBUG_LEVEL >= 2 |
55 | | -#define NIMBLE_LOGW( tag, format, ... ) console_printf("W %s: "#format"\n",tag,##__VA_ARGS__) |
56 | | -#else |
57 | | -#define NIMBLE_LOGW( tag, format, ... ) (void)tag |
58 | | -#endif |
59 | | - |
60 | | -#if CONFIG_NIMBLE_CPP_DEBUG_LEVEL >= 1 |
61 | | -#define NIMBLE_LOGE( tag, format, ... ) console_printf("E %s: "#format"\n",tag,##__VA_ARGS__) |
62 | | -#define NIMBLE_LOGC( tag, format, ... ) console_printf("CRIT %s: "#format"\n",tag,##__VA_ARGS__) |
63 | | -#else |
64 | | -#define NIMBLE_LOGE( tag, format, ... ) (void)tag |
65 | | -#define NIMBLE_LOGC( tag, format, ... ) (void)tag |
66 | | -#endif |
| 35 | +# define NIMBLE_LOGE(tag, format, ...) \ |
| 36 | + NIMBLE_CPP_LOG_PRINT(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__) |
67 | 37 |
|
| 38 | +# define NIMBLE_LOGC(tag, format, ...) \ |
| 39 | + NIMBLE_CPP_LOG_PRINT(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__) |
68 | 40 |
|
| 41 | +#else // using Arduino |
| 42 | +# include "nimble/porting/nimble/include/syscfg/syscfg.h" |
| 43 | +# include "nimble/console/console.h" |
| 44 | +# ifndef CONFIG_NIMBLE_CPP_LOG_LEVEL |
| 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 |
| 50 | +# endif |
| 51 | + |
| 52 | +# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 4 |
| 53 | +# define NIMBLE_LOGD( tag, format, ... ) console_printf("D %s: "#format"\n",tag,##__VA_ARGS__) |
| 54 | +# else |
| 55 | +# define NIMBLE_LOGD( tag, format, ... ) (void)tag |
| 56 | +# endif |
| 57 | + |
| 58 | +# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 3 |
| 59 | +# define NIMBLE_LOGI( tag, format, ... ) console_printf("I %s: "#format"\n",tag,##__VA_ARGS__) |
| 60 | +# else |
| 61 | +# define NIMBLE_LOGI( tag, format, ... ) (void)tag |
| 62 | +# endif |
| 63 | + |
| 64 | +# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 2 |
| 65 | +# define NIMBLE_LOGW( tag, format, ... ) console_printf("W %s: "#format"\n",tag,##__VA_ARGS__) |
| 66 | +# else |
| 67 | +# define NIMBLE_LOGW( tag, format, ... ) (void)tag |
| 68 | +# endif |
| 69 | + |
| 70 | +# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 1 |
| 71 | +# define NIMBLE_LOGE( tag, format, ... ) console_printf("E %s: "#format"\n",tag,##__VA_ARGS__) |
| 72 | +# define NIMBLE_LOGC( tag, format, ... ) console_printf("CRIT %s: "#format"\n",tag,##__VA_ARGS__) |
| 73 | +# else |
| 74 | +# define NIMBLE_LOGE( tag, format, ... ) (void)tag |
| 75 | +# define NIMBLE_LOGC( tag, format, ... ) (void)tag |
| 76 | +# endif |
69 | 77 |
|
70 | 78 | #endif /* CONFIG_NIMBLE_CPP_IDF */ |
71 | 79 | #endif /* CONFIG_BT_ENABLED */ |
|
0 commit comments