1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

cpu/esp32: colored log output

Log module of ESP32 supports colored log outputs when module `esp_log_color` is enabled. The generation of colored log outputs is realized by a extending the bunch of macros with an additional letter indicating the type of log message,
This commit is contained in:
Gunar Schorcht 2019-08-20 16:17:01 +02:00
parent f2f07252fe
commit a3058291b7
2 changed files with 66 additions and 25 deletions

View File

@ -59,6 +59,7 @@ PSEUDOMODULES += esp_hw_counter
PSEUDOMODULES += esp_i2c_sw PSEUDOMODULES += esp_i2c_sw
PSEUDOMODULES += esp_i2c_hw PSEUDOMODULES += esp_i2c_hw
PSEUDOMODULES += esp_idf_newlib PSEUDOMODULES += esp_idf_newlib
PSEUDOMODULES += esp_log_color
PSEUDOMODULES += esp_spi_ram PSEUDOMODULES += esp_spi_ram
PSEUDOMODULES += esp_spiffs PSEUDOMODULES += esp_spiffs
PSEUDOMODULES += esp_wifi_any PSEUDOMODULES += esp_wifi_any

View File

@ -26,48 +26,88 @@
extern "C" { extern "C" {
#endif #endif
#include <stdio.h>
#include <stdint.h>
#include "log.h" #include "log.h"
#define LOG_TAG(level, tag, ...) do { \ extern uint32_t system_get_time_ms (void);
if ((level) <= LOG_LEVEL) log_write_tagged(level, tag, __VA_ARGS__); } while (0U)
#if MODULE_ESP_LOG_COLOR
#define LOG_COLOR_RED "31"
#define LOG_COLOR_GREEN "32"
#define LOG_COLOR_BROWN "33"
#define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
#define LOG_RESET_COLOR "\033[0m"
#define LOG_COLOR_E LOG_COLOR(LOG_COLOR_RED)
#define LOG_COLOR_W LOG_COLOR(LOG_COLOR_BROWN)
#define LOG_COLOR_I LOG_COLOR(LOG_COLOR_GREEN)
#define LOG_COLOR_D
#define LOG_COLOR_V
#else /* MODULE_ESP_LOG_COLOR */
#define LOG_COLOR_E
#define LOG_COLOR_W
#define LOG_COLOR_I
#define LOG_COLOR_D
#define LOG_COLOR_V
#define LOG_RESET_COLOR
#endif /* MODULE_ESP_LOG_COLOR */
#define LOG_FORMAT(letter, format) LOG_COLOR_ ## letter #letter " (%d) [%s] " format LOG_RESET_COLOR
#define LOG_TAG(level, letter, tag, format, ...) \
do { \
if ((unsigned)level <= (unsigned)LOG_LEVEL) { \
printf(LOG_FORMAT(letter, format), system_get_time_ms(), tag, ##__VA_ARGS__); \
} \
} while(0)
#define LOG_TAG_EARLY(level, letter, tag, format, ...) \
do { \
if (LOG_LEVEL >= level) { \
ets_printf(LOG_FORMAT(letter, format), system_get_time_ms(), tag, ##__VA_ARGS__); \
} \
} while(0)
/** /**
* Override LOG_* definitions with a tagged version. By default the function * Override LOG_* definitions with a tagged version. By default the function
* name is used tag. * name is used as tag.
*/ */
#ifndef MODULE_LOG_PRINTFNOFORMAT
#undef LOG_ERROR #undef LOG_ERROR
#undef LOG_INFO #undef LOG_INFO
#undef LOG_WARNING #undef LOG_WARNING
#undef LOG_DEBUG #undef LOG_DEBUG
#define LOG_ERROR(fmt, ...) LOG_TAG(LOG_ERROR , __func__, fmt, ##__VA_ARGS__) #define LOG_ERROR(format, ...) LOG_TAG(LOG_ERROR , E, __func__, format, ##__VA_ARGS__)
#define LOG_WARNING(fmt, ...) LOG_TAG(LOG_WARNING, __func__, fmt, ##__VA_ARGS__) #define LOG_WARNING(format, ...) LOG_TAG(LOG_WARNING, W, __func__, format, ##__VA_ARGS__)
#define LOG_INFO(fmt, ...) LOG_TAG(LOG_INFO , __func__, fmt, ##__VA_ARGS__) #define LOG_INFO(format, ...) LOG_TAG(LOG_INFO , I, __func__, format, ##__VA_ARGS__)
#define LOG_DEBUG(fmt, ...) LOG_TAG(LOG_DEBUG , __func__, fmt, ##__VA_ARGS__) #define LOG_DEBUG(format, ...) LOG_TAG(LOG_DEBUG , D, __func__, format, ##__VA_ARGS__)
#endif
/** Tagged LOG_* definitions */ /** Tagged LOG_* definitions */
#define LOG_TAG_ERROR(tag, fmt, ...) LOG_TAG(LOG_ERROR , tag, fmt, ##__VA_ARGS__) #define LOG_TAG_ERROR(tag, format, ...) LOG_TAG(LOG_ERROR , E, tag, format, ##__VA_ARGS__)
#define LOG_TAG_WARNING(tag, fmt, ...) LOG_TAG(LOG_WARNING, tag, fmt, ##__VA_ARGS__) #define LOG_TAG_WARNING(tag, format, ...) LOG_TAG(LOG_WARNING, W, tag, format, ##__VA_ARGS__)
#define LOG_TAG_INFO(tag, fmt, ...) LOG_TAG(LOG_INFO , tag, fmt, ##__VA_ARGS__) #define LOG_TAG_INFO(tag, format, ...) LOG_TAG(LOG_INFO , I, tag, format, ##__VA_ARGS__)
#define LOG_TAG_DEBUG(tag, fmt, ...) LOG_TAG(LOG_DEBUG , tag, fmt, ##__VA_ARGS__) #define LOG_TAG_DEBUG(tag, format, ...) LOG_TAG(LOG_DEBUG , D, tag, format, ##__VA_ARGS__)
/** definitions for source code compatibility with ESP-IDF */ /** definitions for source code compatibility with ESP-IDF */
#define ESP_EARLY_LOGE(tag, fmt, ...) LOG_TAG(LOG_ERROR , tag, fmt "\n", ##__VA_ARGS__) #define ESP_EARLY_LOGE(tag, format, ...) LOG_TAG_EARLY(LOG_ERROR , E, tag, format "\n", ##__VA_ARGS__)
#define ESP_EARLY_LOGW(tag, fmt, ...) LOG_TAG(LOG_WARNING, tag, fmt "\n", ##__VA_ARGS__) #define ESP_EARLY_LOGW(tag, format, ...) LOG_TAG_EARLY(LOG_WARNING, W, tag, format "\n", ##__VA_ARGS__)
#define ESP_EARLY_LOGI(tag, fmt, ...) LOG_TAG(LOG_INFO , tag, fmt "\n", ##__VA_ARGS__) #define ESP_EARLY_LOGI(tag, format, ...) LOG_TAG_EARLY(LOG_INFO , I, tag, format "\n", ##__VA_ARGS__)
/* #define ESP_LOGE(tag, format, ...) LOG_TAG(LOG_ERROR , E, tag, format "\n", ##__VA_ARGS__)
#define ESP_EARLY_LOGI(tag, fmt, ...) ets_printf("I (%u) %s: " fmt "\n", \ #define ESP_LOGW(tag, format, ...) LOG_TAG(LOG_WARNING, W, tag, format "\n", ##__VA_ARGS__)
system_get_time_ms(), tag, ##__VA_ARGS__) #define ESP_LOGI(tag, format, ...) LOG_TAG(LOG_INFO , I, tag, format "\n", ##__VA_ARGS__)
*/
#define ESP_LOGE(tag, fmt, ...) LOG_TAG(LOG_ERROR , tag, fmt "\n", ##__VA_ARGS__)
#define ESP_LOGW(tag, fmt, ...) LOG_TAG(LOG_WARNING, tag, fmt "\n", ##__VA_ARGS__)
#define ESP_LOGI(tag, fmt, ...) LOG_TAG(LOG_INFO , tag, fmt "\n", ##__VA_ARGS__)
#if ENABLE_DEBUG #if ENABLE_DEBUG
#define ESP_EARLY_LOGD(tag, fmt, ...) LOG_TAG(LOG_DEBUG, tag, fmt "\n", ##__VA_ARGS__) #define ESP_EARLY_LOGD(tag, format, ...) LOG_TAG_EARLY(LOG_DEBUG, D, tag, format "\n", ##__VA_ARGS__)
#define ESP_EARLY_LOGV(tag, fmt, ...) LOG_TAG(LOG_ALL , tag, fmt "\n", ##__VA_ARGS__) #define ESP_EARLY_LOGV(tag, format, ...) LOG_TAG_EARLY(LOG_ALL , V, tag, format "\n", ##__VA_ARGS__)
#define ESP_LOGD(tag, fmt, ...) LOG_TAG(LOG_DEBUG, tag, fmt "\n", ##__VA_ARGS__) #define ESP_LOGD(tag, format, ...) LOG_TAG(LOG_DEBUG, D, tag, format "\n", ##__VA_ARGS__)
#define ESP_LOGV(tag, fmt, ...) LOG_TAG(LOG_ALL , tag, fmt "\n", ##__VA_ARGS__) #define ESP_LOGV(tag, format, ...) LOG_TAG(LOG_ALL , V, tag, format "\n", ##__VA_ARGS__)
#else /* ENABLE_DEBUG */ #else /* ENABLE_DEBUG */