6#ifdef USE_ESPHOME_TASK_LOG_BUFFER
13 this->mutex_ = xSemaphoreCreateMutex();
16size_t TaskLogBuffer::available_contiguous_space_()
const {
17 if (this->head_ >= this->tail_) {
21 size_t space_to_end = CAPACITY - this->head_;
22 if (this->tail_ == 0) {
24 return space_to_end > 0 ? space_to_end - 1 : 0;
30 return this->tail_ - this->head_ - 1;
36 if (this->mutex_ ==
nullptr) {
41 if (xSemaphoreTake(this->mutex_, 0) != pdTRUE) {
45 if (this->head_ == this->tail_) {
46 xSemaphoreGive(this->mutex_);
51 if (CAPACITY - this->tail_ <
sizeof(
LogMessage) ||
57 this->current_message_size_ = message_total_size(msg->text_length);
58 text_length = msg->text_length;
66 this->tail_ += this->current_message_size_;
69 if (this->tail_ >= CAPACITY) {
73 this->message_count_ = this->message_count_ - 1;
74 this->current_message_size_ = 0;
76 xSemaphoreGive(this->mutex_);
80 const char *
format, va_list args) {
83 va_copy(args_copy, args);
89 uint16_t text_length =
ret;
92 size_t total_size = message_total_size(text_length);
95 if (this->mutex_ ==
nullptr) {
100 if (xSemaphoreTake(this->mutex_, 0) != pdTRUE) {
104 size_t write_pos = this->head_;
105 if (this->available_contiguous_space_() < total_size) {
107 if (this->head_ < this->tail_ || this->head_ == 0 || this->tail_ <= total_size) {
108 xSemaphoreGive(this->mutex_);
112 if (CAPACITY - this->head_ >=
sizeof(
LogMessage)) {
123 char *text_area = msg->text_data();
124 ret = vsnprintf(text_area, text_length + 1,
format, args);
127 xSemaphoreGive(this->mutex_);
133 text_area[text_length] =
'\0';
134 msg->text_length = text_length;
136 this->head_ = write_pos + message_total_size(text_length);
137 if (this->head_ >= CAPACITY) {
141 this->message_count_ = this->message_count_ + 1;
143 xSemaphoreGive(this->mutex_);
void release_message_main_loop()
bool borrow_message_main_loop(LogMessage *&message, uint16_t &text_length)
bool send_message_thread_safe(uint8_t level, const char *tag, uint16_t line, const char *thread_name, const char *format, va_list args)
TaskLogMessage LogMessage
static constexpr uint8_t PADDING_MARKER_LEVEL
const LogString * message
int task_log_cap_length(int ret)
void fill_task_log_header(Message *msg, uint8_t level, const char *tag, uint16_t line, const char *thread_name)
uint16_t trim_trailing_newlines(const char *text, uint16_t length)
void const char int const char * format