104 TaskHandle_t task_handle,
const char *format, va_list args) {
107 va_copy(args_copy, args);
108 int ret = vsnprintf(
nullptr, 0, format, args_copy);
116 static constexpr size_t MAX_TEXT_SIZE = 255;
117 size_t text_length = (
static_cast<size_t>(ret) > MAX_TEXT_SIZE) ? MAX_TEXT_SIZE : ret;
120 size_t total_size = message_total_size(text_length);
123 if (this->mutex_ ==
nullptr || this->storage_ ==
nullptr) {
128 if (xSemaphoreTake(this->mutex_, 0) != pdTRUE) {
133 size_t contiguous = this->available_contiguous_space();
135 if (contiguous < total_size) {
138 size_t space_at_start = (this->head_ >= this->tail_) ? this->tail_ : 0;
139 if (space_at_start > 0) {
144 constexpr size_t PADDING_MARKER_MIN_SPACE = offsetof(
LogMessage, level) + 1;
146 if (space_at_start >= total_size && this->head_ > 0 && contiguous >= PADDING_MARKER_MIN_SPACE) {
153 xSemaphoreGive(this->mutex_);
165 const char *thread_name = pcTaskGetTaskName(task_handle);
166 if (thread_name !=
nullptr) {
175 ret = vsnprintf(text_area, text_length + 1, format, args);
178 xSemaphoreGive(this->mutex_);
183 while (text_length > 0 && text_area[text_length - 1] ==
'\n') {
190 this->head_ += total_size;
193 if (this->head_ >= this->size_) {
197 this->message_count_++;
199 xSemaphoreGive(this->mutex_);