diff --git a/cpu/esp32/vendor/esp-idf/esp_funcs.c b/cpu/esp32/vendor/esp-idf/esp_funcs.c index 204eaea107..c2f83ef031 100644 --- a/cpu/esp32/vendor/esp-idf/esp_funcs.c +++ b/cpu/esp32/vendor/esp-idf/esp_funcs.c @@ -86,6 +86,22 @@ uint32_t IRAM_ATTR esp_log_timestamp(void) return system_get_time() / USEC_PER_MSEC; } + +#if MODULE_ESP_LOG_TAGGED +#define ESP_LOG_PREFIX(letter, tag) \ + printf(LOG_COLOR_ ## letter #letter " (%d) [%s] ", \ + system_get_time_ms(), tag) +#else +#define ESP_LOG_PREFIX(letter, tag) \ + printf(LOG_COLOR_ ## letter "[%s] ", tag) +#endif + +#if MODULE_ESP_LOG_COLOR +#define ESP_LOG_SUFFIX() printf(LOG_RESET_COLOR) +#else +#define ESP_LOG_SUFFIX() +#endif + /* * provided by: /path/to/esp-idf/component/log/log.c */ @@ -97,23 +113,16 @@ void IRAM_ATTR esp_log_write(esp_log_level_t level, } char _printf_buf[PRINTF_BUFSIZ]; - const char* prefix = (strchr (format, ':') + 2); - char lc = 'U'; switch (level) { case LOG_NONE : return; - case LOG_ERROR : lc = 'E'; break; - case LOG_WARNING: lc = 'W'; break; - case LOG_INFO : lc = 'I'; break; - case LOG_DEBUG : lc = 'D'; break; - case LOG_ALL : lc = 'V'; break; + case LOG_ERROR : ESP_LOG_PREFIX(E, tag); break; + case LOG_WARNING: ESP_LOG_PREFIX(W, tag); break; + case LOG_INFO : ESP_LOG_PREFIX(I, tag); break; + case LOG_DEBUG : ESP_LOG_PREFIX(D, tag); break; + case LOG_ALL : ESP_LOG_PREFIX(V, tag); break; } - #ifdef LOG_TAG_IN_BRACKETS - ets_printf("%c (%u) [%10s]: ", lc, system_get_time_ms(), tag); - #else - ets_printf("%c (%u) %10s: ", lc, system_get_time_ms(), tag); - #endif va_list arglist; va_start(arglist, format); @@ -124,11 +133,13 @@ void IRAM_ATTR esp_log_write(esp_log_level_t level, int ret = vsnprintf(_printf_buf, PRINTF_BUFSIZ, prefix, arglist); + va_end(arglist); + if (ret > 0) { - ets_printf (_printf_buf); + printf ("%s", _printf_buf); } - va_end(arglist); + ESP_LOG_SUFFIX(); } /* diff --git a/cpu/esp32/vendor/esp-idf/include/log/esp_log.h b/cpu/esp32/vendor/esp-idf/include/log/esp_log.h index 7743c05a7a..f7a5a2e1a7 100644 --- a/cpu/esp32/vendor/esp-idf/include/log/esp_log.h +++ b/cpu/esp32/vendor/esp-idf/include/log/esp_log.h @@ -318,41 +318,36 @@ void esp_log_write(esp_log_level_t level, const char* tag, const char* format, . #include "esp_common.h" -#if 0 /* TODO */ - -#define LOG_FORMAT(letter, format) #letter " (%d) %s: " format "\n" - -#define ESP_LOG_LEVEL(level, tag, format, ...) do { \ - if ((esp_log_level_t)level==ESP_LOG_ERROR ) { \ - esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), \ - esp_log_timestamp(), tag, ##__VA_ARGS__); \ - } \ - else if ((esp_log_level_t)level==ESP_LOG_WARN ) { \ - esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), \ - esp_log_timestamp(), tag, ##__VA_ARGS__); \ - } \ - else if ((esp_log_level_t)level==ESP_LOG_DEBUG ) { \ - esp_log_write(ESP_LOG_DEBUG, tag, LOG_FORMAT(D, format), \ - esp_log_timestamp(), tag, ##__VA_ARGS__); \ - } \ - else if ((esp_log_level_t)level==ESP_LOG_VERBOSE ) { \ - esp_log_write(ESP_LOG_VERBOSE, tag, LOG_FORMAT(V, format), \ - esp_log_timestamp(), tag, ##__VA_ARGS__); \ - } \ - else { \ - esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(I, format), \ - esp_log_timestamp(), tag, ##__VA_ARGS__); \ - } \ - } while(0) - -#define ESP_LOG_LEVEL_LOCAL(level, tag, format, ...) do { \ - if ( LOG_LOCAL_LEVEL >= level ) ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); \ - } while(0) - -#else -#define ESP_LOG_LEVEL_LOCAL(level, tag, format, ...) +#ifndef LOG_LOCAL_LEVEL +#define LOG_LOCAL_LEVEL (esp_log_level_t)LOG_LEVEL #endif +#define ESP_LOG_LEVEL(level, tag, format, ...) \ + do { \ + if ((esp_log_level_t)level==ESP_LOG_ERROR ) { \ + LOG_TAG(level, E, tag, format, ##__VA_ARGS__); \ + } \ + else if ((esp_log_level_t)level==ESP_LOG_WARN ) { \ + LOG_TAG(level, W, tag, format, ##__VA_ARGS__); \ + } \ + else if ((esp_log_level_t)level==ESP_LOG_INFO ) { \ + LOG_TAG(level, I, tag, format, ##__VA_ARGS__); \ + } \ + else if ((esp_log_level_t)level==ESP_LOG_DEBUG ) { \ + LOG_TAG(level, D, tag, format, ##__VA_ARGS__); \ + } \ + else if ((esp_log_level_t)level==ESP_LOG_VERBOSE ) { \ + LOG_TAG(level, V, tag, format, ##__VA_ARGS__); \ + } \ + } while(0) + +#define ESP_LOG_LEVEL_LOCAL(level, tag, format, ...) \ + do { \ + if ( LOG_LOCAL_LEVEL >= level ) { \ + ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); \ + } \ + } while(0) + #endif /* RIOT_VERSION */ #ifdef __cplusplus