ESPHome  2024.11.1
logger_esp8266.cpp
Go to the documentation of this file.
1 #ifdef USE_ESP8266
2 #include "logger.h"
3 #include "esphome/core/log.h"
4 
5 namespace esphome {
6 namespace logger {
7 
8 static const char *const TAG = "logger";
9 
10 void Logger::pre_setup() {
11  if (this->baud_rate_ > 0) {
12  switch (this->uart_) {
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  break;
23  this->hw_serial_ = &Serial1;
24  Serial1.begin(this->baud_rate_);
25  Serial1.setDebugOutput(ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE);
26  break;
27  }
28  } else {
29  uart_set_debug(UART_NO);
30  }
31 
32  global_logger = this;
33 
34  ESP_LOGI(TAG, "Log initialized");
35 }
36 
37 void HOT Logger::write_msg_(const char *msg) { this->hw_serial_->println(msg); }
38 
39 const char *const UART_SELECTIONS[] = {"UART0", "UART1", "UART0_SWAP"};
40 
41 const char *Logger::get_uart_selection_() { return UART_SELECTIONS[this->uart_]; }
42 
43 } // namespace logger
44 } // namespace esphome
45 #endif
Logger * global_logger
Definition: logger.cpp:198
const char * get_uart_selection_()
UARTSelection uart_
Definition: logger.h:151
void pre_setup()
Set up this component.
const char *const UART_SELECTIONS[]
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void write_msg_(const char *msg)