1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-16 14:55:50 +00:00
This commit is contained in:
J. Nick Koston
2025-11-15 18:17:50 -06:00
parent d5d61546e7
commit d64bcf27b3
2 changed files with 8 additions and 7 deletions

View File

@@ -137,16 +137,14 @@ void Logger::log_vprintf_(uint8_t level, const char *tag, int line, const __Flas
this->format_log_to_buffer_with_terminator_(level, tag, line, this->tx_buffer_, args, this->tx_buffer_, this->format_log_to_buffer_with_terminator_(level, tag, line, this->tx_buffer_, args, this->tx_buffer_,
&this->tx_buffer_at_, this->tx_buffer_size_); &this->tx_buffer_at_, this->tx_buffer_size_);
size_t msg_length = uint16_t msg_length =
this->tx_buffer_at_ - msg_start; // Don't subtract 1 - tx_buffer_at_ is already at the null terminator position this->tx_buffer_at_ - msg_start; // Don't subtract 1 - tx_buffer_at_ is already at the null terminator position
// Callbacks get message first (before console write) // Callbacks get message first (before console write)
this->log_callback_.call(level, tag, this->tx_buffer_ + msg_start, msg_length); this->log_callback_.call(level, tag, this->tx_buffer_ + msg_start, msg_length);
// Write to console starting at the msg_start // Write to console starting at the msg_start
if (this->baud_rate_ > 0) { this->write_tx_buffer_to_console_(msg_start, &msg_length);
this->write_msg_(this->tx_buffer_ + msg_start, msg_length);
}
global_recursion_guard_ = false; global_recursion_guard_ = false;
} }

View File

@@ -231,10 +231,13 @@ class Logger : public Component {
} }
// Helper to write tx_buffer_ to console if logging is enabled // Helper to write tx_buffer_ to console if logging is enabled
inline void HOT write_tx_buffer_to_console_() { // offset: starting position in tx_buffer_ (default 0)
// length: pointer to length of message at offset (updated with newline if added)
inline void HOT write_tx_buffer_to_console_(uint32_t offset = 0, uint16_t *length = nullptr) {
if (this->baud_rate_ > 0) { if (this->baud_rate_ > 0) {
this->add_newline_to_buffer_if_needed_(this->tx_buffer_, &this->tx_buffer_at_, this->tx_buffer_size_); uint16_t *len_ptr = length ? length : &this->tx_buffer_at_;
this->write_msg_(this->tx_buffer_, this->tx_buffer_at_); this->add_newline_to_buffer_if_needed_(this->tx_buffer_ + offset, len_ptr, this->tx_buffer_size_ - offset);
this->write_msg_(this->tx_buffer_ + offset, *len_ptr);
} }
} }