esp-nimble-cpp / NimBLE-Arduino  1.3.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 "sdkconfig.h"
12 
13 #if defined(CONFIG_BT_ENABLED)
14 
15 #ifdef ARDUINO_ARCH_ESP32
16 #include "syscfg/syscfg.h"
17 #include "modlog/modlog.h"
18 
19 // If Arduino is being used, strip out the colors and ignore log printing below ui setting.
20 // Note: because CONFIG_LOG_DEFAULT_LEVEL is set at ERROR in Arduino we must use MODLOG_DFLT(ERROR
21 // otherwise no messages will be printed above that level.
22 
23 #ifndef CORE_DEBUG_LEVEL
24 #define CORE_DEBUG_LEVEL CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL
25 #endif
26 
27 #if CORE_DEBUG_LEVEL >= 4
28 #define NIMBLE_LOGD( tag, format, ... ) MODLOG_DFLT(ERROR, "D %s: "#format"\n",tag,##__VA_ARGS__)
29 #else
30 #define NIMBLE_LOGD( tag, format, ... ) (void)tag
31 #endif
32 
33 #if CORE_DEBUG_LEVEL >= 3
34 #define NIMBLE_LOGI( tag, format, ... ) MODLOG_DFLT(ERROR, "I %s: "#format"\n",tag,##__VA_ARGS__)
35 #else
36 #define NIMBLE_LOGI( tag, format, ... ) (void)tag
37 #endif
38 
39 #if CORE_DEBUG_LEVEL >= 2
40 #define NIMBLE_LOGW( tag, format, ... ) MODLOG_DFLT(ERROR, "W %s: "#format"\n",tag,##__VA_ARGS__)
41 #else
42 #define NIMBLE_LOGW( tag, format, ... ) (void)tag
43 #endif
44 
45 #if CORE_DEBUG_LEVEL >= 1
46 #define NIMBLE_LOGE( tag, format, ... ) MODLOG_DFLT(ERROR, "E %s: "#format"\n",tag,##__VA_ARGS__)
47 #else
48 #define NIMBLE_LOGE( tag, format, ... ) (void)tag
49 #endif
50 
51 #define NIMBLE_LOGC( tag, format, ... ) MODLOG_DFLT(CRITICAL, "CRIT %s: "#format"\n",tag,##__VA_ARGS__)
52 
53 #else
54 
55 #include "esp_log.h"
56 
57 #define NIMBLE_LOGE(tag, format, ...) ESP_LOGE(tag, format, ##__VA_ARGS__)
58 #define NIMBLE_LOGW(tag, format, ...) ESP_LOGW(tag, format, ##__VA_ARGS__)
59 #define NIMBLE_LOGI(tag, format, ...) ESP_LOGI(tag, format, ##__VA_ARGS__)
60 #define NIMBLE_LOGD(tag, format, ...) ESP_LOGD(tag, format, ##__VA_ARGS__)
61 #define NIMBLE_LOGC(tag, format, ...) ESP_LOGE(tag, format, ##__VA_ARGS__)
62 
63 #endif /*ARDUINO_ARCH_ESP32*/
64 
65 #endif /*CONFIG_BT_ENABLED*/
66 #endif /*MAIN_NIMBLELOG_H_*/