diff --git a/esphome/components/logger/logger.cpp b/esphome/components/logger/logger.cpp index 2e86c00b7ed..e8df5fbb167 100644 --- a/esphome/components/logger/logger.cpp +++ b/esphome/components/logger/logger.cpp @@ -102,9 +102,7 @@ void Logger::log_vprintf_non_main_thread_(uint8_t level, const char *tag, int li uint16_t console_pos; LogBuffer buf(console_buffer, console_pos, MAX_CONSOLE_LOG_MSG_SIZE); this->format_log_to_buffer_with_terminator_(level, tag, line, format, args, buf); - // Add newline before writing to console - buf.add_newline(); - this->write_msg_(buf); + this->write_to_console_(buf); } // RAII guard automatically resets on return diff --git a/esphome/components/logger/logger.h b/esphome/components/logger/logger.h index 15e72175651..f3c26395e85 100644 --- a/esphome/components/logger/logger.h +++ b/esphome/components/logger/logger.h @@ -450,12 +450,16 @@ class Logger : public Component { #endif } + // Helper to write log buffer to console (adds newline and writes) + inline void HOT write_to_console_(LogBuffer &buf) { + buf.add_newline(); + this->write_msg_(buf); + } + // Helper to write log buffer to console if logging is enabled inline void HOT write_log_buffer_to_console_(LogBuffer &buf) { - if (this->baud_rate_ > 0) { - buf.add_newline(); - this->write_msg_(buf); - } + if (this->baud_rate_ > 0) + this->write_to_console_(buf); } // Helper to format and send a log message to both console and listeners