1
- // Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
1
+ // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2
2
//
3
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
4
// you may not use this file except in compliance with the License.
11
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
-
15
14
#ifndef __ARDUHAL_LOG_H__
16
15
#define __ARDUHAL_LOG_H__
17
16
@@ -37,6 +36,9 @@ extern "C"
37
36
#define ARDUHAL_LOG_LEVEL CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL
38
37
#else
39
38
#define ARDUHAL_LOG_LEVEL CORE_DEBUG_LEVEL
39
+ #ifdef USE_ESP_IDF_LOG
40
+ #define LOG_LOCAL_LEVEL CORE_DEBUG_LEVEL
41
+ #endif
40
42
#endif
41
43
42
44
#ifndef CONFIG_ARDUHAL_LOG_COLORS
@@ -72,62 +74,101 @@ extern "C"
72
74
#define ARDUHAL_LOG_RESET_COLOR
73
75
#endif
74
76
77
+
78
+
75
79
const char * pathToFileName (const char * path );
76
80
int log_printf (const char * fmt , ...);
77
81
78
82
#define ARDUHAL_SHORT_LOG_FORMAT (letter , format ) ARDUHAL_LOG_COLOR_ ## letter format ARDUHAL_LOG_RESET_COLOR "\r\n"
79
83
#define ARDUHAL_LOG_FORMAT (letter , format ) ARDUHAL_LOG_COLOR_ ## letter "[" #letter "][%s:%u] %s(): " format ARDUHAL_LOG_RESET_COLOR "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__
80
84
81
85
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE
86
+ #ifndef USE_ESP_IDF_LOG
82
87
#define log_v (format , ...) log_printf(ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__)
83
88
#define isr_log_v (format , ...) ets_printf(ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__)
84
89
#else
90
+ #define log_v (format , ...) do {log_to_esp(TAG, ESP_LOG_VERBOSE, format, ##__VA_ARGS__);}while(0)
91
+ #define isr_log_v (format , ...) do {ets_printf(LOG_FORMAT(V, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0)
92
+ #endif
93
+ #else
85
94
#define log_v (format , ...)
86
95
#define isr_log_v (format , ...)
87
96
#endif
88
97
89
98
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
99
+ #ifndef USE_ESP_IDF_LOG
90
100
#define log_d (format , ...) log_printf(ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__)
91
101
#define isr_log_d (format , ...) ets_printf(ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__)
92
102
#else
103
+ #define log_d (format , ...) do {log_to_esp(TAG, ESP_LOG_DEBUG, format, ##__VA_ARGS__);}while(0)
104
+ #define isr_log_d (format , ...) do {ets_printf(LOG_FORMAT(D, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0)
105
+ #endif
106
+ #else
93
107
#define log_d (format , ...)
94
108
#define isr_log_d (format , ...)
95
109
#endif
96
110
97
111
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
112
+ #ifndef USE_ESP_IDF_LOG
98
113
#define log_i (format , ...) log_printf(ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__)
99
114
#define isr_log_i (format , ...) ets_printf(ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__)
100
115
#else
116
+ #define log_i (format , ...) do {log_to_esp(TAG, ESP_LOG_INFO, format, ##__VA_ARGS__);}while(0)
117
+ #define isr_log_i (format , ...) do {ets_printf(LOG_FORMAT(I, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0)
118
+ #endif
119
+ #else
101
120
#define log_i (format , ...)
102
121
#define isr_log_i (format , ...)
103
122
#endif
104
123
105
124
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_WARN
125
+ #ifndef USE_ESP_IDF_LOG
106
126
#define log_w (format , ...) log_printf(ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__)
107
127
#define isr_log_w (format , ...) ets_printf(ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__)
108
128
#else
129
+ #define log_w (format , ...) do {log_to_esp(TAG, ESP_LOG_WARN, format, ##__VA_ARGS__);}while(0)
130
+ #define isr_log_w (format , ...) do {ets_printf(LOG_FORMAT(W, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0)
131
+ #endif
132
+ #else
109
133
#define log_w (format , ...)
110
134
#define isr_log_w (format , ...)
111
135
#endif
112
136
113
137
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
138
+ #ifndef USE_ESP_IDF_LOG
114
139
#define log_e (format , ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
115
140
#define isr_log_e (format , ...) ets_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
116
141
#else
142
+ #define log_e (format , ...) do {log_to_esp(TAG, ESP_LOG_ERROR, format, ##__VA_ARGS__);}while(0)
143
+ #define isr_log_e (format , ...) do {ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0)
144
+ #endif
145
+ #else
117
146
#define log_e (format , ...)
118
147
#define isr_log_e (format , ...)
119
148
#endif
120
149
121
150
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_NONE
151
+ #ifndef USE_ESP_IDF_LOG
122
152
#define log_n (format , ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
123
153
#define isr_log_n (format , ...) ets_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__)
124
154
#else
155
+ #define log_n (format , ...) do {log_to_esp(TAG, ESP_LOG_ERROR, format, ##__VA_ARGS__);}while(0)
156
+ #define isr_log_n (format , ...) do {ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__);}while(0)
157
+ #endif
158
+ #else
125
159
#define log_n (format , ...)
126
160
#define isr_log_n (format , ...)
127
161
#endif
128
162
129
163
#include "esp_log.h"
130
164
165
+ #ifdef USE_ESP_IDF_LOG
166
+ #ifndef TAG
167
+ #define TAG "ARDUINO"
168
+ #endif
169
+ void log_to_esp (char * tag , esp_log_level_t level , const char * format , ...);
170
+ //#define log_n(format, ...) myLog(ESP_LOG_NONE, format, ##__VA_ARGS__)
171
+ #else
131
172
#ifdef CONFIG_ARDUHAL_ESP_LOG
132
173
#undef ESP_LOGE
133
174
#undef ESP_LOGW
@@ -151,6 +192,7 @@ int log_printf(const char *fmt, ...);
151
192
#define ESP_EARLY_LOGD (tag , ...) isr_log_d(__VA_ARGS__)
152
193
#define ESP_EARLY_LOGV (tag , ...) isr_log_v(__VA_ARGS__)
153
194
#endif
195
+ #endif
154
196
155
197
#ifdef __cplusplus
156
198
}
0 commit comments