esp-nimble-cpp  1.4.1
NimBLELog.h
1 /*
2  * NimBLELog.h
3  *
4  * Created: on Feb 24 2020
5  * Author H2zero
6  *
7  */
8 #ifndef MAIN_NIMBLELOG_H_
9 #define MAIN_NIMBLELOG_H_
10 
11 #include "nimconfig.h"
12 
13 #if defined(CONFIG_BT_ENABLED)
14 
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
20 
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)
25 
26 # define NIMBLE_LOGD(tag, format, ...) \
27  NIMBLE_CPP_LOG_PRINT(ESP_LOG_DEBUG, tag, format, ##__VA_ARGS__)
28 
29 # define NIMBLE_LOGI(tag, format, ...) \
30  NIMBLE_CPP_LOG_PRINT(ESP_LOG_INFO, tag, format, ##__VA_ARGS__)
31 
32 # define NIMBLE_LOGW(tag, format, ...) \
33  NIMBLE_CPP_LOG_PRINT(ESP_LOG_WARN, tag, format, ##__VA_ARGS__)
34 
35 # define NIMBLE_LOGE(tag, format, ...) \
36  NIMBLE_CPP_LOG_PRINT(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__)
37 
38 # define NIMBLE_LOGC(tag, format, ...) \
39  NIMBLE_CPP_LOG_PRINT(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__)
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
77 
78 #endif /* CONFIG_NIMBLE_CPP_IDF */
79 #endif /* CONFIG_BT_ENABLED */
80 #endif /* MAIN_NIMBLELOG_H_ */