diff --git a/esphome/components/logger/logger.h b/esphome/components/logger/logger.h index a8fa0f34a7..1678fed5f5 100644 --- a/esphome/components/logger/logger.h +++ b/esphome/components/logger/logger.h @@ -418,7 +418,7 @@ class Logger : public Component { #endif #endif void process_messages_(); - void write_msg_(const LogBuffer &buf); + void write_msg_(const char *msg, uint16_t len); // Format a log message with printf-style arguments and write it to a buffer with header, footer, and null terminator inline void HOT format_log_to_buffer_with_terminator_(uint8_t level, const char *tag, int line, const char *format, @@ -455,7 +455,7 @@ class Logger : public Component { // Helper to write log buffer to console (replaces null terminator with newline and writes) inline void HOT write_to_console_(LogBuffer &buf) { buf.terminate_with_newline(); - this->write_msg_(buf); + this->write_msg_(buf.data, buf.pos); } // Helper to write log buffer to console if logging is enabled diff --git a/esphome/components/logger/logger_esp32.cpp b/esphome/components/logger/logger_esp32.cpp index 4d186d950e..dfa643d5e9 100644 --- a/esphome/components/logger/logger_esp32.cpp +++ b/esphome/components/logger/logger_esp32.cpp @@ -118,7 +118,7 @@ void Logger::pre_setup() { ESP_LOGI(TAG, "Log initialized"); } -void HOT Logger::write_msg_(const LogBuffer &buf) { +void HOT Logger::write_msg_(const char *msg, uint16_t len) { #if defined(USE_LOGGER_UART_SELECTION_USB_CDC) || defined(USE_LOGGER_UART_SELECTION_USB_SERIAL_JTAG) // USB CDC/JTAG - single write including newline (already in buffer) // Use fwrite to stdout which goes through VFS to USB console @@ -128,10 +128,10 @@ void HOT Logger::write_msg_(const LogBuffer &buf) { // This is compile-time selection, not runtime detection - if USB is configured, it's always used. // There is no fallback to regular UART if "USB isn't connected" - that's the user's responsibility // to configure correctly for their hardware. This approach eliminates runtime overhead. - fwrite(buf.data, 1, buf.pos, stdout); + fwrite(msg, 1, len, stdout); #else // Regular UART - single write including newline (already in buffer) - uart_write_bytes(this->uart_num_, buf.data, buf.pos); + uart_write_bytes(this->uart_num_, msg, len); #endif } diff --git a/esphome/components/logger/logger_esp8266.cpp b/esphome/components/logger/logger_esp8266.cpp index 84474dd9df..0a3433d132 100644 --- a/esphome/components/logger/logger_esp8266.cpp +++ b/esphome/components/logger/logger_esp8266.cpp @@ -28,9 +28,9 @@ void Logger::pre_setup() { ESP_LOGI(TAG, "Log initialized"); } -void HOT Logger::write_msg_(const LogBuffer &buf) { +void HOT Logger::write_msg_(const char *msg, uint16_t len) { // Single write with newline already in buffer (added by caller) - this->hw_serial_->write(buf.data, buf.pos); + this->hw_serial_->write(msg, len); } const LogString *Logger::get_uart_selection_() { diff --git a/esphome/components/logger/logger_host.cpp b/esphome/components/logger/logger_host.cpp index 612b47b9a9..be12b6df6a 100644 --- a/esphome/components/logger/logger_host.cpp +++ b/esphome/components/logger/logger_host.cpp @@ -3,7 +3,7 @@ namespace esphome::logger { -void HOT Logger::write_msg_(const LogBuffer &buf) { +void HOT Logger::write_msg_(const char *msg, uint16_t len) { static constexpr size_t TIMESTAMP_LEN = 10; // "[HH:MM:SS]" // tx_buffer_size_ defaults to 512, so 768 covers default + headroom char buffer[TIMESTAMP_LEN + 768]; @@ -15,8 +15,8 @@ void HOT Logger::write_msg_(const LogBuffer &buf) { size_t pos = strftime(buffer, TIMESTAMP_LEN + 1, "[%H:%M:%S]", &timeinfo); // Copy message (with newline already included by caller) - size_t copy_len = std::min(static_cast(buf.pos), sizeof(buffer) - pos); - memcpy(buffer + pos, buf.data, copy_len); + size_t copy_len = std::min(static_cast(len), sizeof(buffer) - pos); + memcpy(buffer + pos, msg, copy_len); pos += copy_len; // Single write for everything diff --git a/esphome/components/logger/logger_libretiny.cpp b/esphome/components/logger/logger_libretiny.cpp index 8635407845..aab8a97abf 100644 --- a/esphome/components/logger/logger_libretiny.cpp +++ b/esphome/components/logger/logger_libretiny.cpp @@ -49,7 +49,7 @@ void Logger::pre_setup() { ESP_LOGI(TAG, "Log initialized"); } -void HOT Logger::write_msg_(const LogBuffer &buf) { this->hw_serial_->write(buf.data, buf.pos); } +void HOT Logger::write_msg_(const char *msg, uint16_t len) { this->hw_serial_->write(msg, len); } const LogString *Logger::get_uart_selection_() { switch (this->uart_) { diff --git a/esphome/components/logger/logger_rp2040.cpp b/esphome/components/logger/logger_rp2040.cpp index fc210f0bdd..1f435031f6 100644 --- a/esphome/components/logger/logger_rp2040.cpp +++ b/esphome/components/logger/logger_rp2040.cpp @@ -27,9 +27,9 @@ void Logger::pre_setup() { ESP_LOGI(TAG, "Log initialized"); } -void HOT Logger::write_msg_(const LogBuffer &buf) { +void HOT Logger::write_msg_(const char *msg, uint16_t len) { // Single write with newline already in buffer (added by caller) - this->hw_serial_->write(buf.data, buf.pos); + this->hw_serial_->write(msg, len); } const LogString *Logger::get_uart_selection_() { diff --git a/esphome/components/logger/logger_zephyr.cpp b/esphome/components/logger/logger_zephyr.cpp index 9676c44485..ef1702c5c1 100644 --- a/esphome/components/logger/logger_zephyr.cpp +++ b/esphome/components/logger/logger_zephyr.cpp @@ -63,18 +63,18 @@ void Logger::pre_setup() { ESP_LOGI(TAG, "Log initialized"); } -void HOT Logger::write_msg_(const LogBuffer &buf) { +void HOT Logger::write_msg_(const char *msg, uint16_t len) { // Single write with newline already in buffer (added by caller) #ifdef CONFIG_PRINTK // Requires the debug component and an active SWD connection. // It is used for pyocd rtt -t nrf52840 - k_str_out(const_cast(buf.data), buf.pos); + k_str_out(const_cast(msg), len); #endif if (this->uart_dev_ == nullptr) { return; } - for (uint16_t i = 0; i < buf.pos; ++i) { - uart_poll_out(this->uart_dev_, buf.data[i]); + for (uint16_t i = 0; i < len; ++i) { + uart_poll_out(this->uart_dev_, msg[i]); } }