Skip to content

Commit 8a2ca2b

Browse files
committed
Provide a default TAG name for USE_ESP_IDF_LOG
The ESP-IDF logging library has some nice features such as log forwarding. esp32-hal-log.h has long supported the USE_ESP_IDF_LOG macro, but due to subsequent changes, it requires a global TAG preprocessor macro to be defined. The macro name is too generic and just having a sane default would be preferable.
1 parent d164df8 commit 8a2ca2b

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

Diff for: cores/esp32/esp32-hal-log.h

+25-24
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ extern "C" {
8080
#define ARDUHAL_LOG_COLOR_PRINT_END
8181
#endif
8282

83+
#ifdef USE_ESP_IDF_LOG
84+
#ifndef ARDUHAL_ESP_LOG_TAG
85+
#define ARDUHAL_ESP_LOG_TAG "ARDUINO"
86+
#endif
87+
#endif
88+
8389
const char *pathToFileName(const char *path);
8490
int log_printf(const char *fmt, ...);
8591
void log_print_buf(const uint8_t *b, size_t len);
@@ -104,15 +110,15 @@ void log_print_buf(const uint8_t *b, size_t len);
104110
#else
105111
#define log_v(format, ...) \
106112
do { \
107-
ESP_LOG_LEVEL_LOCAL(ESP_LOG_VERBOSE, TAG, format, ##__VA_ARGS__); \
113+
ESP_LOG_LEVEL_LOCAL(ESP_LOG_VERBOSE, ARDUHAL_ESP_LOG_TAG, format, ##__VA_ARGS__); \
108114
} while (0)
109115
#define isr_log_v(format, ...) \
110116
do { \
111-
ets_printf(LOG_FORMAT(V, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \
117+
ets_printf(LOG_FORMAT(V, format), esp_log_timestamp(), ARDUHAL_ESP_LOG_TAG, ##__VA_ARGS__); \
112118
} while (0)
113119
#define log_buf_v(b, l) \
114120
do { \
115-
ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_VERBOSE); \
121+
ESP_LOG_BUFFER_HEXDUMP(ARDUHAL_ESP_LOG_TAG, b, l, ESP_LOG_VERBOSE); \
116122
} while (0)
117123
#endif
118124
#else
@@ -140,15 +146,15 @@ void log_print_buf(const uint8_t *b, size_t len);
140146
#else
141147
#define log_d(format, ...) \
142148
do { \
143-
ESP_LOG_LEVEL_LOCAL(ESP_LOG_DEBUG, TAG, format, ##__VA_ARGS__); \
149+
ESP_LOG_LEVEL_LOCAL(ESP_LOG_DEBUG, ARDUHAL_ESP_LOG_TAG, format, ##__VA_ARGS__); \
144150
} while (0)
145151
#define isr_log_d(format, ...) \
146152
do { \
147-
ets_printf(LOG_FORMAT(D, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \
153+
ets_printf(LOG_FORMAT(D, format), esp_log_timestamp(), ARDUHAL_ESP_LOG_TAG, ##__VA_ARGS__); \
148154
} while (0)
149155
#define log_buf_d(b, l) \
150156
do { \
151-
ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_DEBUG); \
157+
ESP_LOG_BUFFER_HEXDUMP(ARDUHAL_ESP_LOG_TAG, b, l, ESP_LOG_DEBUG); \
152158
} while (0)
153159
#endif
154160
#else
@@ -176,15 +182,15 @@ void log_print_buf(const uint8_t *b, size_t len);
176182
#else
177183
#define log_i(format, ...) \
178184
do { \
179-
ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, TAG, format, ##__VA_ARGS__); \
185+
ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, ARDUHAL_ESP_LOG_TAG, format, ##__VA_ARGS__); \
180186
} while (0)
181187
#define isr_log_i(format, ...) \
182188
do { \
183-
ets_printf(LOG_FORMAT(I, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \
189+
ets_printf(LOG_FORMAT(I, format), esp_log_timestamp(), ARDUHAL_ESP_LOG_TAG, ##__VA_ARGS__); \
184190
} while (0)
185191
#define log_buf_i(b, l) \
186192
do { \
187-
ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_INFO); \
193+
ESP_LOG_BUFFER_HEXDUMP(ARDUHAL_ESP_LOG_TAG, b, l, ESP_LOG_INFO); \
188194
} while (0)
189195
#endif
190196
#else
@@ -212,15 +218,15 @@ void log_print_buf(const uint8_t *b, size_t len);
212218
#else
213219
#define log_w(format, ...) \
214220
do { \
215-
ESP_LOG_LEVEL_LOCAL(ESP_LOG_WARN, TAG, format, ##__VA_ARGS__); \
221+
ESP_LOG_LEVEL_LOCAL(ESP_LOG_WARN, ARDUHAL_ESP_LOG_TAG, format, ##__VA_ARGS__); \
216222
} while (0)
217223
#define isr_log_w(format, ...) \
218224
do { \
219-
ets_printf(LOG_FORMAT(W, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \
225+
ets_printf(LOG_FORMAT(W, format), esp_log_timestamp(), ARDUHAL_ESP_LOG_TAG, ##__VA_ARGS__); \
220226
} while (0)
221227
#define log_buf_w(b, l) \
222228
do { \
223-
ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_WARN); \
229+
ESP_LOG_BUFFER_HEXDUMP(ARDUHAL_ESP_LOG_TAG, b, l, ESP_LOG_WARN); \
224230
} while (0)
225231
#endif
226232
#else
@@ -248,15 +254,15 @@ void log_print_buf(const uint8_t *b, size_t len);
248254
#else
249255
#define log_e(format, ...) \
250256
do { \
251-
ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, TAG, format, ##__VA_ARGS__); \
257+
ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, ARDUHAL_ESP_LOG_TAG, format, ##__VA_ARGS__); \
252258
} while (0)
253259
#define isr_log_e(format, ...) \
254260
do { \
255-
ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \
261+
ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), ARDUHAL_ESP_LOG_TAG, ##__VA_ARGS__); \
256262
} while (0)
257263
#define log_buf_e(b, l) \
258264
do { \
259-
ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR); \
265+
ESP_LOG_BUFFER_HEXDUMP(ARDUHAL_ESP_LOG_TAG, b, l, ESP_LOG_ERROR); \
260266
} while (0)
261267
#endif
262268
#else
@@ -284,15 +290,15 @@ void log_print_buf(const uint8_t *b, size_t len);
284290
#else
285291
#define log_n(format, ...) \
286292
do { \
287-
ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, TAG, format, ##__VA_ARGS__); \
293+
ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, ARDUHAL_ESP_LOG_TAG, format, ##__VA_ARGS__); \
288294
} while (0)
289295
#define isr_log_n(format, ...) \
290296
do { \
291-
ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \
297+
ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), ARDUHAL_ESP_LOG_TAG, ##__VA_ARGS__); \
292298
} while (0)
293299
#define log_buf_n(b, l) \
294300
do { \
295-
ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR); \
301+
ESP_LOG_BUFFER_HEXDUMP(ARDUHAL_ESP_LOG_TAG, b, l, ESP_LOG_ERROR); \
296302
} while (0)
297303
#endif
298304
#else
@@ -309,12 +315,7 @@ void log_print_buf(const uint8_t *b, size_t len);
309315

310316
#include "esp_log.h"
311317

312-
#ifdef USE_ESP_IDF_LOG
313-
//#ifndef TAG
314-
//#define TAG "ARDUINO"
315-
//#endif
316-
//#define log_n(format, ...) myLog(ESP_LOG_NONE, format, ##__VA_ARGS__)
317-
#else
318+
#ifndef USE_ESP_IDF_LOG
318319
#ifdef CONFIG_ARDUHAL_ESP_LOG
319320
#undef ESP_LOGE
320321
#undef ESP_LOGW

0 commit comments

Comments
 (0)