1
0
mirror of https://github.com/esphome/esphome.git synced 2026-02-08 08:41:59 +00:00

api change not needed now

This commit is contained in:
J. Nick Koston
2026-02-04 08:47:35 +01:00
parent c9dfaa36b4
commit 5ef8a90aa0
7 changed files with 17 additions and 17 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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_() {

View File

@@ -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<size_t>(buf.pos), sizeof(buffer) - pos);
memcpy(buffer + pos, buf.data, copy_len);
size_t copy_len = std::min(static_cast<size_t>(len), sizeof(buffer) - pos);
memcpy(buffer + pos, msg, copy_len);
pos += copy_len;
// Single write for everything

View File

@@ -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_) {

View File

@@ -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_() {

View File

@@ -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<char *>(buf.data), buf.pos);
k_str_out(const_cast<char *>(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]);
}
}