9#ifdef USE_ESPHOME_TASK_LOG_BUFFER
11static inline uint32_t total_size_in_32bit_words(uint16_t text_length) {
16static inline uint32_t get_wlen(
const mpsc_pbuf_generic *item) {
31 const char *
format, va_list args) {
34 va_copy(args_copy, args);
40 uint16_t text_length =
ret;
41 size_t total_size = total_size_in_32bit_words(text_length);
42 auto *msg =
reinterpret_cast<LogMessage *
>(mpsc_pbuf_alloc(&this->
log_buffer_, total_size, K_NO_WAIT));
50 char *text_area = msg->text_data();
51 ret = vsnprintf(text_area, text_length + 1,
format, args);
58 for (
size_t i = 0; i < text_length; ++i) {
61 text_area[text_length] = 0;
65 msg->text_length = text_length;
67 mpsc_pbuf_commit(&this->
log_buffer_,
reinterpret_cast<mpsc_pbuf_generic *
>(msg));
72 if (this->current_token_) {
76 this->current_token_ = mpsc_pbuf_claim(&this->
log_buffer_);
78 if (this->current_token_ ==
nullptr) {
91 if (this->current_token_ ==
nullptr) {
94 mpsc_pbuf_free(&this->
log_buffer_, this->current_token_);
95 this->current_token_ =
nullptr;
void release_message_main_loop()
mpsc_pbuf_buffer log_buffer_
mpsc_pbuf_buffer_config mpsc_config_
static constexpr size_t BUF_WORD_COUNT
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
uint32_t buf_storage_[BUF_WORD_COUNT]
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)
__thread bool non_main_task_recursion_guard
uint16_t trim_trailing_newlines(const char *text, uint16_t length)
void const char int const char * format