From d94b32ed20abf33796e4deca3be3fa5bf99b7d60 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Mon, 27 May 2024 16:34:40 +0300 Subject: [PATCH] fix(esp-hal-log):Provide a default TAG name for USE_ESP_IDF_LOG logging macro (#9686) * change(logging): 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. * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- cores/esp32/esp32-hal-log.h | 121 ++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 60 deletions(-) diff --git a/cores/esp32/esp32-hal-log.h b/cores/esp32/esp32-hal-log.h index fda406fac3c..b8810c8bba9 100644 --- a/cores/esp32/esp32-hal-log.h +++ b/cores/esp32/esp32-hal-log.h @@ -80,6 +80,12 @@ extern "C" { #define ARDUHAL_LOG_COLOR_PRINT_END #endif +#ifdef USE_ESP_IDF_LOG +#ifndef ARDUHAL_ESP_LOG_TAG +#define ARDUHAL_ESP_LOG_TAG "ARDUINO" +#endif +#endif + const char *pathToFileName(const char *path); int log_printf(const char *fmt, ...); void log_print_buf(const uint8_t *b, size_t len); @@ -102,17 +108,17 @@ void log_print_buf(const uint8_t *b, size_t len); ARDUHAL_LOG_COLOR_PRINT_END; \ } while (0) #else -#define log_v(format, ...) \ - do { \ - ESP_LOG_LEVEL_LOCAL(ESP_LOG_VERBOSE, TAG, format, ##__VA_ARGS__); \ +#define log_v(format, ...) \ + do { \ + ESP_LOG_LEVEL_LOCAL(ESP_LOG_VERBOSE, ARDUHAL_ESP_LOG_TAG, format, ##__VA_ARGS__); \ } while (0) -#define isr_log_v(format, ...) \ - do { \ - ets_printf(LOG_FORMAT(V, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \ +#define isr_log_v(format, ...) \ + do { \ + ets_printf(LOG_FORMAT(V, format), esp_log_timestamp(), ARDUHAL_ESP_LOG_TAG, ##__VA_ARGS__); \ } while (0) -#define log_buf_v(b, l) \ - do { \ - ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_VERBOSE); \ +#define log_buf_v(b, l) \ + do { \ + ESP_LOG_BUFFER_HEXDUMP(ARDUHAL_ESP_LOG_TAG, b, l, ESP_LOG_VERBOSE); \ } while (0) #endif #else @@ -138,17 +144,17 @@ void log_print_buf(const uint8_t *b, size_t len); ARDUHAL_LOG_COLOR_PRINT_END; \ } while (0) #else -#define log_d(format, ...) \ - do { \ - ESP_LOG_LEVEL_LOCAL(ESP_LOG_DEBUG, TAG, format, ##__VA_ARGS__); \ +#define log_d(format, ...) \ + do { \ + ESP_LOG_LEVEL_LOCAL(ESP_LOG_DEBUG, ARDUHAL_ESP_LOG_TAG, format, ##__VA_ARGS__); \ } while (0) -#define isr_log_d(format, ...) \ - do { \ - ets_printf(LOG_FORMAT(D, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \ +#define isr_log_d(format, ...) \ + do { \ + ets_printf(LOG_FORMAT(D, format), esp_log_timestamp(), ARDUHAL_ESP_LOG_TAG, ##__VA_ARGS__); \ } while (0) -#define log_buf_d(b, l) \ - do { \ - ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_DEBUG); \ +#define log_buf_d(b, l) \ + do { \ + ESP_LOG_BUFFER_HEXDUMP(ARDUHAL_ESP_LOG_TAG, b, l, ESP_LOG_DEBUG); \ } while (0) #endif #else @@ -174,17 +180,17 @@ void log_print_buf(const uint8_t *b, size_t len); ARDUHAL_LOG_COLOR_PRINT_END; \ } while (0) #else -#define log_i(format, ...) \ - do { \ - ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, TAG, format, ##__VA_ARGS__); \ +#define log_i(format, ...) \ + do { \ + ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, ARDUHAL_ESP_LOG_TAG, format, ##__VA_ARGS__); \ } while (0) -#define isr_log_i(format, ...) \ - do { \ - ets_printf(LOG_FORMAT(I, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \ +#define isr_log_i(format, ...) \ + do { \ + ets_printf(LOG_FORMAT(I, format), esp_log_timestamp(), ARDUHAL_ESP_LOG_TAG, ##__VA_ARGS__); \ } while (0) -#define log_buf_i(b, l) \ - do { \ - ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_INFO); \ +#define log_buf_i(b, l) \ + do { \ + ESP_LOG_BUFFER_HEXDUMP(ARDUHAL_ESP_LOG_TAG, b, l, ESP_LOG_INFO); \ } while (0) #endif #else @@ -210,17 +216,17 @@ void log_print_buf(const uint8_t *b, size_t len); ARDUHAL_LOG_COLOR_PRINT_END; \ } while (0) #else -#define log_w(format, ...) \ - do { \ - ESP_LOG_LEVEL_LOCAL(ESP_LOG_WARN, TAG, format, ##__VA_ARGS__); \ +#define log_w(format, ...) \ + do { \ + ESP_LOG_LEVEL_LOCAL(ESP_LOG_WARN, ARDUHAL_ESP_LOG_TAG, format, ##__VA_ARGS__); \ } while (0) -#define isr_log_w(format, ...) \ - do { \ - ets_printf(LOG_FORMAT(W, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \ +#define isr_log_w(format, ...) \ + do { \ + ets_printf(LOG_FORMAT(W, format), esp_log_timestamp(), ARDUHAL_ESP_LOG_TAG, ##__VA_ARGS__); \ } while (0) -#define log_buf_w(b, l) \ - do { \ - ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_WARN); \ +#define log_buf_w(b, l) \ + do { \ + ESP_LOG_BUFFER_HEXDUMP(ARDUHAL_ESP_LOG_TAG, b, l, ESP_LOG_WARN); \ } while (0) #endif #else @@ -246,17 +252,17 @@ void log_print_buf(const uint8_t *b, size_t len); ARDUHAL_LOG_COLOR_PRINT_END; \ } while (0) #else -#define log_e(format, ...) \ - do { \ - ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, TAG, format, ##__VA_ARGS__); \ +#define log_e(format, ...) \ + do { \ + ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, ARDUHAL_ESP_LOG_TAG, format, ##__VA_ARGS__); \ } while (0) -#define isr_log_e(format, ...) \ - do { \ - ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \ +#define isr_log_e(format, ...) \ + do { \ + ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), ARDUHAL_ESP_LOG_TAG, ##__VA_ARGS__); \ } while (0) -#define log_buf_e(b, l) \ - do { \ - ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR); \ +#define log_buf_e(b, l) \ + do { \ + ESP_LOG_BUFFER_HEXDUMP(ARDUHAL_ESP_LOG_TAG, b, l, ESP_LOG_ERROR); \ } while (0) #endif #else @@ -282,17 +288,17 @@ void log_print_buf(const uint8_t *b, size_t len); ARDUHAL_LOG_COLOR_PRINT_END; \ } while (0) #else -#define log_n(format, ...) \ - do { \ - ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, TAG, format, ##__VA_ARGS__); \ +#define log_n(format, ...) \ + do { \ + ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, ARDUHAL_ESP_LOG_TAG, format, ##__VA_ARGS__); \ } while (0) -#define isr_log_n(format, ...) \ - do { \ - ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), TAG, ##__VA_ARGS__); \ +#define isr_log_n(format, ...) \ + do { \ + ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), ARDUHAL_ESP_LOG_TAG, ##__VA_ARGS__); \ } while (0) -#define log_buf_n(b, l) \ - do { \ - ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR); \ +#define log_buf_n(b, l) \ + do { \ + ESP_LOG_BUFFER_HEXDUMP(ARDUHAL_ESP_LOG_TAG, b, l, ESP_LOG_ERROR); \ } while (0) #endif #else @@ -309,12 +315,7 @@ void log_print_buf(const uint8_t *b, size_t len); #include "esp_log.h" -#ifdef USE_ESP_IDF_LOG -//#ifndef TAG -//#define TAG "ARDUINO" -//#endif -//#define log_n(format, ...) myLog(ESP_LOG_NONE, format, ##__VA_ARGS__) -#else +#ifndef USE_ESP_IDF_LOG #ifdef CONFIG_ARDUHAL_ESP_LOG #undef ESP_LOGE #undef ESP_LOGW