ESPHome
2026.4.0-dev
Loading...
Searching...
No Matches
esphome
components
logger
logger_esp32.h
Go to the documentation of this file.
1
#pragma once
2
3
#ifdef USE_ESP32
4
#include "
esphome/core/helpers.h
"
5
#include <driver/uart.h>
6
7
namespace
esphome::logger
{
8
9
inline
void
HOT
Logger::write_msg_
(
const
char
*msg, uint16_t
len
) {
10
#if defined(USE_LOGGER_UART_SELECTION_USB_CDC) || defined(USE_LOGGER_UART_SELECTION_USB_SERIAL_JTAG)
11
// USB CDC/JTAG - single write including newline (already in buffer)
12
// Use fwrite to stdout which goes through VFS to USB console
13
//
14
// Note: These defines indicate the user's YAML configuration choice (hardware_uart: USB_CDC/USB_SERIAL_JTAG).
15
// They are ONLY defined when the user explicitly selects USB as the logger output in their config.
16
// This is compile-time selection, not runtime detection - if USB is configured, it's always used.
17
// There is no fallback to regular UART if "USB isn't connected" - that's the user's responsibility
18
// to configure correctly for their hardware. This approach eliminates runtime overhead.
19
fwrite(msg, 1,
len
, stdout);
20
#else
21
// Regular UART - single write including newline (already in buffer)
22
uart_write_bytes(this->
uart_num_
, msg,
len
);
23
#endif
24
}
25
26
}
// namespace esphome::logger
27
28
#endif
esphome::logger::Logger::write_msg_
void write_msg_(const char *msg, uint16_t len)
Definition
logger_esp32.h:9
esphome::logger::Logger::uart_num_
uart_port_t uart_num_
Definition
logger.h:334
helpers.h
esphome::logger
Definition
log_buffer.h:7
esphome::len
std::string size_t len
Definition
helpers.h:1045
Generated by
1.12.0