11 static const char *
const TAG =
"logger";
13 static const char *
const LOG_LEVEL_COLORS[] = {
15 ESPHOME_LOG_BOLD(ESPHOME_LOG_COLOR_RED),
16 ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_YELLOW),
17 ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_GREEN),
18 ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_MAGENTA),
19 ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_CYAN),
20 ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_GRAY),
21 ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_WHITE),
23 static const char *
const LOG_LEVEL_LETTERS[] = {
40 const char *color = LOG_LEVEL_COLORS[level];
41 const char *letter = LOG_LEVEL_LETTERS[level];
42 #if defined(USE_ESP32) || defined(USE_LIBRETINY) 43 TaskHandle_t current_task = xTaskGetCurrentTaskHandle();
45 void *current_task =
nullptr;
50 const char *thread_name =
"";
51 #if defined(USE_ESP32) 52 thread_name = pcTaskGetName(current_task);
53 #elif defined(USE_LIBRETINY) 54 thread_name = pcTaskGetTaskName(current_task);
57 ESPHOME_LOG_BOLD(ESPHOME_LOG_COLOR_RED), thread_name, color);
73 #ifdef USE_STORE_LOG_STR_IN_FLASH 82 auto *format_pgm_p =
reinterpret_cast<const uint8_t *
>(format);
113 return ESPHOME_LOG_LEVEL;
136 if (xPortGetFreeHeapSize() < 2048)
146 #if defined(USE_ESP32) || defined(USE_LIBRETINY) 147 this->
main_task_ = xTaskGetCurrentTaskHandle();
151 #ifdef USE_LOGGER_USB_CDC 157 static bool opened =
false;
158 if (opened == Serial) {
161 if (
false == opened) {
174 #if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040) || defined(USE_LIBRETINY) 182 const char *
const LOG_LEVELS[] = {
"NONE",
"ERROR",
"WARN",
"INFO",
"CONFIG",
"DEBUG",
"VERBOSE",
"VERY_VERBOSE"};
185 ESP_LOGCONFIG(TAG,
"Logger:");
186 ESP_LOGCONFIG(TAG,
" Level: %s", LOG_LEVELS[ESPHOME_LOG_LEVEL]);
188 ESP_LOGCONFIG(TAG,
" Log Baud Rate: %" PRIu32, this->
baud_rate_);
193 ESP_LOGCONFIG(TAG,
" Level for '%s': %s", it.tag.c_str(), LOG_LEVELS[it.level]);
void set_baud_rate(uint32_t baud_rate)
Manually set the baud rate for serial, set to 0 to disable.
void add_on_log_callback(std::function< void(int, const char *, const char *)> &&callback)
Register a callback that will be called for every log message sent.
UARTSelection
Enum for logging UART selection.
int level_for(const char *tag)
void log_vprintf_(int level, const char *tag, int line, const char *format, va_list args)
void vprintf_to_buffer_(const char *format, va_list args)
void dump_config() override
float get_setup_priority() const override
Logger(uint32_t baud_rate, size_t tx_buffer_size)
void write_header_(int level, const char *tag, int line)
const float BUS
For communication buses like i2c/spi.
UARTSelection get_uart() const
Get the UART used by the logger.
void schedule_dump_config()
void set_null_terminator_()
const char * get_uart_selection_()
void printf_to_buffer_(const char *format,...)
void write_to_buffer_(char value)
Application App
Global storage of Application pointer - only one Application can exist.
const char *const LOG_LEVELS[]
uint8_t progmem_read_byte(const uint8_t *addr)
void log_message_(int level, const char *tag, int offset=0)
Implementation of SPI Controller mode.
std::vector< LogLevelOverride > log_levels_
void set_log_level(const std::string &tag, int log_level)
Set the log level of the specified tag.
void write_msg_(const char *msg)
bool recursion_guard_
Prevents recursive log calls, if true a log message is already being processed.
CallbackManager< void(int, const char *, const char *)> log_callback_
bool is_buffer_full_() const