Logging Engine

esphomelib will by default log to both Serial (with baud rate 115200).

API Reference


class LogComponent : public Component

A simple component that enables logging to Serial via the ESP_LOG* macros.

This component should optimally be setup very early because only after its setup log messages are actually sent. To do this, simply call pre_setup() as early as possible.

Public Functions

LogComponent(uint32_t baud_rate = 11520, size_t tx_buffer_size = 512)

Construct the LogComponent.

  • baud_rate: The baud_rate for the serial interface. 0 to disable UART logging.
  • tx_buffer_size: The buffer size (in bytes) used for constructing log messages.

void set_baud_rate(uint32_t baud_rate)

Manually set the baud rate for serial, set to 0 to disable.

void set_tx_buffer_size(size_t tx_buffer_size)

Set the buffer size that’s used for constructing log messages. Log messages longer than this will be truncated.

void set_global_log_level(int log_level)

Set the global log level. Note: Use the ESPHOMELIB_LOG_LEVEL define to also remove the logs from the build.

void set_log_level(const std::string &tag, int log_level)

Set the log level of the specified tag.

void pre_setup()

Set up this component.

uint32_t get_baud_rate() const
size_t get_tx_buffer_size() const
int log_vprintf_(int level, const char *tag, const char *format, va_list args)
void add_on_log_callback(std::function<void(int, const char *)> &&callback)

Register a callback that will be called for every log message sent.

float get_setup_priority() const

priority of setup().

higher -> executed earlier

Defaults to 0.

The setup priority of this component

Protected Attributes

uint32_t baud_rate_
std::vector<char> tx_buffer_
int global_log_level_ = {ESPHOMELIB_LOG_LEVEL}
std::vector<LogLevelOverride> log_levels_
CallbackManager<void(int, const char *)> log_callback_ = {}
struct LogLevelOverride

Public Members

std::string tag
int level