mirror of
https://github.com/esphome/esphome.git
synced 2026-02-18 23:45:40 -07:00
fix
This commit is contained in:
@@ -55,8 +55,11 @@ void HOT Logger::log_vprintf_(uint8_t level, const char *tag, int line, const ch
|
||||
// ESP32/LibreTiny: use TaskHandle_t overload to avoid redundant xTaskGetCurrentTaskHandle()
|
||||
// (we already have the handle from the main task check above).
|
||||
// Host: pass a stack buffer for pthread_getname_np to write into.
|
||||
#if defined(USE_ESP32) || defined(USE_LIBRETINY) || defined(USE_ZEPHYR)
|
||||
#if defined(USE_ESP32) || defined(USE_LIBRETINY)
|
||||
const char *thread_name = get_thread_name_(current_task);
|
||||
#elif defined(USE_ZEPHYR)
|
||||
char thread_name_buf[MAX_POINTER_REPRESENTATION];
|
||||
const char *thread_name = get_thread_name_(thread_name_buf, current_task);
|
||||
#else // USE_HOST
|
||||
char thread_name_buf[THREAD_NAME_BUF_SIZE];
|
||||
const char *thread_name = this->get_thread_name_(thread_name_buf);
|
||||
|
||||
@@ -591,8 +591,10 @@ class Logger : public Component {
|
||||
}
|
||||
|
||||
#elif defined(USE_ZEPHYR)
|
||||
const char *HOT get_thread_name_(std::span<char> buff) {
|
||||
k_tid_t current_task = k_current_get();
|
||||
const char *HOT get_thread_name_(std::span<char> buff, k_tid_t current_task = nullptr) {
|
||||
if (current_task == nullptr) {
|
||||
current_task = k_current_get();
|
||||
}
|
||||
if (current_task == main_task_) {
|
||||
return nullptr; // Main task
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ TaskLogBufferZephyr::TaskLogBufferZephyr(size_t total_buffer_size) {
|
||||
|
||||
TaskLogBufferZephyr::~TaskLogBufferZephyr() { delete[] this->mpsc_config_.buf; }
|
||||
|
||||
bool TaskLogBufferZephyr::send_message_thread_safe(uint8_t level, const char *tag, uint16_t line, void *task_handle,
|
||||
const char *format, va_list args) {
|
||||
bool TaskLogBufferZephyr::send_message_thread_safe(uint8_t level, const char *tag, uint16_t line,
|
||||
const char *thread_name, const char *format, va_list args) {
|
||||
// First, calculate the exact length needed using a null buffer (no actual writing)
|
||||
va_list args_copy;
|
||||
va_copy(args_copy, args);
|
||||
@@ -51,12 +51,7 @@ bool TaskLogBufferZephyr::send_message_thread_safe(uint8_t level, const char *ta
|
||||
msg->level = level;
|
||||
msg->tag = tag;
|
||||
msg->line = line;
|
||||
const char *thread_name = k_thread_name_get(static_cast<k_tid_t>(task_handle));
|
||||
if (thread_name) {
|
||||
strncpy(msg->thread_name, thread_name, sizeof(msg->thread_name) - 1);
|
||||
} else {
|
||||
std::snprintf(msg->thread_name, sizeof(msg->thread_name), "%p", task_handle);
|
||||
}
|
||||
strncpy(msg->thread_name, thread_name, sizeof(msg->thread_name) - 1);
|
||||
|
||||
// Format the message text directly into the acquired memory
|
||||
// We add 1 to text_length to ensure space for null terminator during formatting
|
||||
|
||||
@@ -52,8 +52,8 @@ class TaskLogBufferZephyr {
|
||||
void release_message_main_loop();
|
||||
|
||||
// Thread-safe - send a message to the ring buffer from any thread
|
||||
bool send_message_thread_safe(uint8_t level, const char *tag, uint16_t line, void *task_handle, const char *format,
|
||||
va_list args);
|
||||
bool send_message_thread_safe(uint8_t level, const char *tag, uint16_t line, const char *thread_name,
|
||||
const char *format, va_list args);
|
||||
|
||||
protected:
|
||||
mpsc_pbuf_buffer_config mpsc_config_{};
|
||||
|
||||
Reference in New Issue
Block a user