Closed
Description
The problem
If a task is created using xTaskCreate()
and the task creates log entries with ESP_LOG
, not all will be visible in the log.
Reason:
The logger omits the entry, if another task is creating an entry at the same time.
recursion_guard_
https://github.com/esphome/esphome/blob/45276cc24452b7ea1a7a0c6f88ed11ca38a4a1e6/esphome/components/logger/logger.cpp#L67
Possible fix:
Replace recursion_guard_
with a mutex created by xSemaphoreCreateMutex
and claim/release it with xSemaphoreTake
and xSemaphoreGive
.
Working PoC:
static SemaphoreHandle_t log_guard = xSemaphoreCreateMutex();
void HOT Logger::log_vprintf_(int level, const char *tag, int line, const char *format, va_list args) { // NOLINT
if (level > this->level_for(tag))
return;
xSemaphoreTake(log_guard, portMAX_DELAY);
this->reset_buffer_();
this->write_header_(level, tag, line);
this->vprintf_to_buffer_(format, args);
this->write_footer_();
this->log_message_(level, tag);
xSemaphoreGive(log_guard);
}
Which version of ESPHome has the issue?
2023.10.6
What type of installation are you using?
pip
Which version of Home Assistant has the issue?
No response
What platform are you using?
ESP32
Board
esp32dev
Component causing the issue
logger
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response