ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
logger_esp8266.cpp
Go to the documentation of this file.
1#ifdef USE_ESP8266
2#include "logger.h"
4#ifdef USE_ESP8266_CRASH_HANDLER
6#endif
7#include "esphome/core/log.h"
8
9namespace esphome::logger {
10
11ESPHOME_LOG_TAG(TAG, "logger");
12
13void Logger::pre_setup() {
14#if defined(USE_ESP8266_LOGGER_SERIAL)
15 this->hw_serial_ = &Serial;
16 Serial.begin(this->baud_rate_);
17 if (this->uart_ == UART_SELECTION_UART0_SWAP) {
18 Serial.swap();
19 }
20 Serial.setDebugOutput(ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE);
21#elif defined(USE_ESP8266_LOGGER_SERIAL1)
22 this->hw_serial_ = &Serial1;
23 Serial1.begin(this->baud_rate_);
24 Serial1.setDebugOutput(ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE);
25#else
26 // No serial logging - disable debug output
27 uart_set_debug(UART_NO);
28#endif
29
30 global_logger = this;
31
32 ESP_LOGI(TAG, "Log initialized");
33#ifdef USE_ESP8266_CRASH_HANDLER
35#endif
36}
37
38const LogString *Logger::get_uart_selection_() {
39#if defined(USE_ESP8266_LOGGER_SERIAL)
40 if (this->uart_ == UART_SELECTION_UART0_SWAP) {
41 return LOG_STR("UART0_SWAP");
42 }
43 return LOG_STR("UART0");
44#elif defined(USE_ESP8266_LOGGER_SERIAL1)
45 return LOG_STR("UART1");
46#else
47 return LOG_STR("NONE");
48#endif
49}
50
51#ifdef USE_CRASH_HANDLER
54#endif
55
56} // namespace esphome::logger
57
58#if !defined(USE_ESP8266_LOGGER_SERIAL) && !defined(USE_ESP8266_LOGGER_SERIAL1)
59// With serial logging disabled, ROM ets_putc still writes to the physical UART0
60// at whatever baud rate a uart bus configured there; uart_set_debug(UART_NO)
61// only silences the installable putc1 hook, not ets_putc itself. Blocking
62// writes at a low baud rate (for example 4800 for a power monitoring chip) can
63// starve the soft watchdog. All linked callers (newlib stdout, lwIP
64// diagnostics, postmortem dumps) are redirected here by -Wl,--wrap=ets_putc.
65// IRAM_ATTR because the ROM original is callable with the flash cache
66// disabled (for example from newlib's _write_r, which is placed in IRAM).
67extern "C" void IRAM_ATTR __wrap_ets_putc(char) {}
68#endif
69
70#endif
UARTSelection uart_
Definition logger.h:362
const LogString * get_uart_selection_()
void pre_setup()
Set up this component.
void IRAM_ATTR __wrap_ets_putc(char)
bool crash_handler_has_data()
Returns true if the previous boot was a crash (exception, WDT, or soft WDT).
void crash_handler_log()
Log crash data if a crash was detected on previous boot.
bool crash_log_pending()
Whether a crash record from before this boot is waiting to be reported.
@ UART_SELECTION_UART0_SWAP
Definition logger.h:127
Logger * global_logger
Definition logger.cpp:276
void log_crash_to_client()
Log the previous crash for a client that just subscribed to the logs.
ESPHOME_LOG_TAG(TAG, "logger")