Make logger string memory usage more efficient (#641)

* Make logger string storing more efficient

* Lint
This commit is contained in:
Otto Winter 2019-06-16 19:14:24 +02:00 committed by GitHub
parent c13f132399
commit 904a0b26ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 155 additions and 100 deletions

View file

@ -140,7 +140,7 @@ bool ESP32BLETracker::ble_setup() {
void ESP32BLETracker::start_scan(bool first) { void ESP32BLETracker::start_scan(bool first) {
if (!xSemaphoreTake(this->scan_end_lock_, 0L)) { if (!xSemaphoreTake(this->scan_end_lock_, 0L)) {
ESP_LOGW("Cannot start scan!"); ESP_LOGW(TAG, "Cannot start scan!");
return; return;
} }

View file

@ -29,7 +29,7 @@ LOG_LEVEL_TO_ESP_LOG = {
'VERY_VERBOSE': cg.global_ns.ESP_LOGVV, 'VERY_VERBOSE': cg.global_ns.ESP_LOGVV,
} }
LOG_LEVEL_SEVERITY = ['NONE', 'ERROR', 'WARN', 'INFO', 'DEBUG', 'VERBOSE', 'VERY_VERBOSE'] LOG_LEVEL_SEVERITY = ['NONE', 'ERROR', 'WARN', 'INFO', 'CONFIG', 'DEBUG', 'VERBOSE', 'VERY_VERBOSE']
UART_SELECTION_ESP32 = ['UART0', 'UART1', 'UART2'] UART_SELECTION_ESP32 = ['UART0', 'UART1', 'UART2']

View file

@ -10,38 +10,74 @@ namespace logger {
static const char *TAG = "logger"; static const char *TAG = "logger";
int HOT Logger::log_vprintf_(int level, const char *tag, const char *format, va_list args) { // NOLINT static const char *LOG_LEVEL_COLORS[] = {
if (level > this->level_for(tag)) "", // NONE
return 0; ESPHOME_LOG_BOLD(ESPHOME_LOG_COLOR_RED), // ERROR
ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_YELLOW), // WARNING
ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_GREEN), // INFO
ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_MAGENTA), // CONFIG
ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_CYAN), // DEBUG
ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_GRAY), // VERBOSE
ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_WHITE), // VERY_VERBOSE
};
static const char *LOG_LEVEL_LETTERS[] = {
"", // NONE
"E", // ERROR
"W", // WARNING
"I", // INFO
"C", // CONFIG
"D", // DEBUG
"V", // VERBOSE
"VV", // VERY_VERBOSE
};
int ret = vsnprintf(this->tx_buffer_.data(), this->tx_buffer_.capacity(), format, args); void Logger::write_header_(int level, const char *tag, int line) {
this->log_message_(level, tag, this->tx_buffer_.data(), ret); if (level < 0)
return ret; level = 0;
if (level > 7)
level = 7;
const char *color = LOG_LEVEL_COLORS[level];
const char *letter = LOG_LEVEL_LETTERS[level];
this->printf_to_buffer_("%s[%s][%s:%03u]: ", color, letter, tag, line);
}
void HOT Logger::log_vprintf_(int level, const char *tag, int line, const char *format, va_list args) { // NOLINT
if (level > this->level_for(tag))
return;
this->reset_buffer_();
this->write_header_(level, tag, line);
this->vprintf_to_buffer_(format, args);
this->write_footer_();
this->log_message_(level, tag);
} }
#ifdef USE_STORE_LOG_STR_IN_FLASH #ifdef USE_STORE_LOG_STR_IN_FLASH
int Logger::log_vprintf_(int level, const char *tag, const __FlashStringHelper *format, va_list args) { // NOLINT void Logger::log_vprintf_(int level, const char *tag, int line, const __FlashStringHelper *format,
va_list args) { // NOLINT
if (level > this->level_for(tag)) if (level > this->level_for(tag))
return 0; return;
this->reset_buffer_();
// copy format string // copy format string
const char *format_pgm_p = (PGM_P) format; const char *format_pgm_p = (PGM_P) format;
size_t len = 0; size_t len = 0;
char *write = this->tx_buffer_.data();
char ch = '.'; char ch = '.';
while (len < this->tx_buffer_.capacity() && ch != '\0') { while (!this->is_buffer_full_() && ch != '\0') {
*write++ = ch = pgm_read_byte(format_pgm_p++); this->tx_buffer_[this->tx_buffer_at_++] = ch = pgm_read_byte(format_pgm_p++);
len++;
} }
if (len == this->tx_buffer_.capacity()) // Buffer full form copying format
return -1; if (this->is_buffer_full_())
return;
// length of format string, includes null terminator
uint32_t offset = this->tx_buffer_at_;
// now apply vsnprintf // now apply vsnprintf
size_t offset = len + 1; this->write_header_(level, tag, line);
size_t remaining = this->tx_buffer_.capacity() - offset; this->vprintf_to_buffer_(this->tx_buffer_, args);
char *msg = this->tx_buffer_.data() + offset; this->write_footer_();
int ret = vsnprintf(msg, remaining, this->tx_buffer_.data(), args); this->log_message_(level, tag, offset);
this->log_message_(level, tag, msg, ret);
return ret;
} }
#endif #endif
@ -54,22 +90,26 @@ int HOT Logger::level_for(const char *tag) {
return it.level; return it.level;
} }
} }
return this->global_log_level_; return ESPHOME_LOG_LEVEL;
} }
void HOT Logger::log_message_(int level, const char *tag, char *msg, int ret) { void HOT Logger::log_message_(int level, const char *tag, int offset) {
if (ret <= 0)
return;
// remove trailing newline // remove trailing newline
if (msg[ret - 1] == '\n') { if (this->tx_buffer_[this->tx_buffer_at_ - 1] == '\n') {
msg[ret - 1] = '\0'; this->tx_buffer_at_--;
} }
// make sure null terminator is present
this->set_null_terminator_();
const char *msg = this->tx_buffer_ + offset;
if (this->baud_rate_ > 0) if (this->baud_rate_ > 0)
this->hw_serial_->println(msg); this->hw_serial_->println(msg);
this->log_callback_.call(level, tag, msg); this->log_callback_.call(level, tag, msg);
} }
Logger::Logger(uint32_t baud_rate, size_t tx_buffer_size, UARTSelection uart) : baud_rate_(baud_rate), uart_(uart) { Logger::Logger(uint32_t baud_rate, size_t tx_buffer_size, UARTSelection uart)
this->set_tx_buffer_size(tx_buffer_size); : baud_rate_(baud_rate), tx_buffer_size_(tx_buffer_size), uart_(uart) {
// add 1 to buffer size for null terminator
this->tx_buffer_ = new char[this->tx_buffer_size_ + 1];
} }
void Logger::pre_setup() { void Logger::pre_setup() {
@ -96,7 +136,7 @@ void Logger::pre_setup() {
if (this->uart_ == UART_SELECTION_UART0_SWAP) { if (this->uart_ == UART_SELECTION_UART0_SWAP) {
this->hw_serial_->swap(); this->hw_serial_->swap();
} }
this->hw_serial_->setDebugOutput(this->global_log_level_ >= ESPHOME_LOG_LEVEL_VERBOSE); this->hw_serial_->setDebugOutput(ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE);
#endif #endif
} }
#ifdef ARDUINO_ARCH_ESP8266 #ifdef ARDUINO_ARCH_ESP8266
@ -108,7 +148,7 @@ void Logger::pre_setup() {
global_logger = this; global_logger = this;
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
esp_log_set_vprintf(esp_idf_log_vprintf_); esp_log_set_vprintf(esp_idf_log_vprintf_);
if (this->global_log_level_ >= ESPHOME_LOG_LEVEL_VERBOSE) { if (ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE) {
esp_log_level_set("*", ESP_LOG_VERBOSE); esp_log_level_set("*", ESP_LOG_VERBOSE);
} }
#endif #endif
@ -116,17 +156,15 @@ void Logger::pre_setup() {
ESP_LOGI(TAG, "Log initialized"); ESP_LOGI(TAG, "Log initialized");
} }
void Logger::set_baud_rate(uint32_t baud_rate) { this->baud_rate_ = baud_rate; } void Logger::set_baud_rate(uint32_t baud_rate) { this->baud_rate_ = baud_rate; }
void Logger::set_global_log_level(int log_level) { this->global_log_level_ = log_level; }
void Logger::set_log_level(const std::string &tag, int log_level) { void Logger::set_log_level(const std::string &tag, int log_level) {
this->log_levels_.push_back(LogLevelOverride{tag, log_level}); this->log_levels_.push_back(LogLevelOverride{tag, log_level});
} }
void Logger::set_tx_buffer_size(size_t tx_buffer_size) { this->tx_buffer_.reserve(tx_buffer_size); }
UARTSelection Logger::get_uart() const { return this->uart_; } UARTSelection Logger::get_uart() const { return this->uart_; }
void Logger::add_on_log_callback(std::function<void(int, const char *, const char *)> &&callback) { void Logger::add_on_log_callback(std::function<void(int, const char *, const char *)> &&callback) {
this->log_callback_.add(std::move(callback)); this->log_callback_.add(std::move(callback));
} }
float Logger::get_setup_priority() const { return setup_priority::HARDWARE - 1.0f; } float Logger::get_setup_priority() const { return setup_priority::HARDWARE - 1.0f; }
const char *LOG_LEVELS[] = {"NONE", "ERROR", "WARN", "INFO", "DEBUG", "VERBOSE", "VERY_VERBOSE"}; const char *LOG_LEVELS[] = {"NONE", "ERROR", "WARN", "INFO", "CONFIG", "DEBUG", "VERBOSE", "VERY_VERBOSE"};
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32
const char *UART_SELECTIONS[] = {"UART0", "UART1", "UART2"}; const char *UART_SELECTIONS[] = {"UART0", "UART1", "UART2"};
#endif #endif
@ -135,13 +173,14 @@ const char *UART_SELECTIONS[] = {"UART0", "UART1", "UART0_SWAP"};
#endif #endif
void Logger::dump_config() { void Logger::dump_config() {
ESP_LOGCONFIG(TAG, "Logger:"); ESP_LOGCONFIG(TAG, "Logger:");
ESP_LOGCONFIG(TAG, " Level: %s", LOG_LEVELS[this->global_log_level_]); ESP_LOGCONFIG(TAG, " Level: %s", LOG_LEVELS[ESPHOME_LOG_LEVEL]);
ESP_LOGCONFIG(TAG, " Log Baud Rate: %u", this->baud_rate_); ESP_LOGCONFIG(TAG, " Log Baud Rate: %u", this->baud_rate_);
ESP_LOGCONFIG(TAG, " Hardware UART: %s", UART_SELECTIONS[this->uart_]); ESP_LOGCONFIG(TAG, " Hardware UART: %s", UART_SELECTIONS[this->uart_]);
for (auto &it : this->log_levels_) { for (auto &it : this->log_levels_) {
ESP_LOGCONFIG(TAG, " Level for '%s': %s", it.tag.c_str(), LOG_LEVELS[it.level]); ESP_LOGCONFIG(TAG, " Level for '%s': %s", it.tag.c_str(), LOG_LEVELS[it.level]);
} }
} }
void Logger::write_footer_() { this->write_to_buffer_(ESPHOME_LOG_RESET_COLOR, strlen(ESPHOME_LOG_RESET_COLOR)); }
Logger *global_logger = nullptr; Logger *global_logger = nullptr;

View file

@ -31,16 +31,9 @@ class Logger : public Component {
/// Manually set the baud rate for serial, set to 0 to disable. /// Manually set the baud rate for serial, set to 0 to disable.
void set_baud_rate(uint32_t baud_rate); void set_baud_rate(uint32_t baud_rate);
/// Set the buffer size that's used for constructing log messages. Log messages longer than this will be truncated.
void set_tx_buffer_size(size_t tx_buffer_size);
/// Get the UART used by the logger. /// Get the UART used by the logger.
UARTSelection get_uart() const; UARTSelection get_uart() const;
/// Set the global log level. Note: Use the ESPHOME_LOG_LEVEL define to also remove the logs from the build.
void set_global_log_level(int log_level);
int get_global_log_level() const { return this->global_log_level_; }
/// Set the log level of the specified tag. /// Set the log level of the specified tag.
void set_log_level(const std::string &tag, int log_level); void set_log_level(const std::string &tag, int log_level);
@ -57,17 +50,58 @@ class Logger : public Component {
float get_setup_priority() const override; float get_setup_priority() const override;
int log_vprintf_(int level, const char *tag, const char *format, va_list args); // NOLINT void log_vprintf_(int level, const char *tag, int line, const char *format, va_list args); // NOLINT
#ifdef USE_STORE_LOG_STR_IN_FLASH #ifdef USE_STORE_LOG_STR_IN_FLASH
int log_vprintf_(int level, const char *tag, const __FlashStringHelper *format, va_list args); // NOLINT void log_vprintf_(int level, const char *tag, int line, const __FlashStringHelper *format, va_list args); // NOLINT
#endif #endif
protected: protected:
void log_message_(int level, const char *tag, char *msg, int ret); void write_header_(int level, const char *tag, int line);
void write_footer_();
void log_message_(int level, const char *tag, int offset = 0);
inline bool is_buffer_full_() const { return this->tx_buffer_at_ >= this->tx_buffer_size_; }
inline int buffer_remaining_capacity_() const { return this->tx_buffer_size_ - this->tx_buffer_at_; }
inline void reset_buffer_() { this->tx_buffer_at_ = 0; }
inline void set_null_terminator_() {
// does not increment buffer_at
this->tx_buffer_[this->tx_buffer_at_] = '\0';
}
inline void write_to_buffer_(char value) {
if (!this->is_buffer_full_())
this->tx_buffer_[this->tx_buffer_at_++] = value;
}
inline void write_to_buffer_(const char *value, int length) {
for (int i = 0; i < length && !this->is_buffer_full_(); i++) {
this->tx_buffer_[this->tx_buffer_at_++] = value[i];
}
}
inline void vprintf_to_buffer_(const char *format, va_list args) {
if (this->is_buffer_full_())
return;
int remaining = this->buffer_remaining_capacity_();
int ret = vsnprintf(this->tx_buffer_ + this->tx_buffer_at_, remaining, format, args);
if (ret < 0) {
// Encoding error, do not increment buffer_at
return;
}
if (ret >= remaining) {
// output was too long, truncated
ret = remaining;
}
this->tx_buffer_at_ += ret;
}
inline void printf_to_buffer_(const char *format, ...) {
va_list arg;
va_start(arg, format);
this->vprintf_to_buffer_(format, arg);
va_end(arg);
}
uint32_t baud_rate_; uint32_t baud_rate_;
std::vector<char> tx_buffer_; char *tx_buffer_{nullptr};
int global_log_level_{ESPHOME_LOG_LEVEL}; int tx_buffer_at_{0};
int tx_buffer_size_{0};
UARTSelection uart_{UART_SELECTION_UART0}; UARTSelection uart_{UART_SELECTION_UART0};
HardwareSerial *hw_serial_{nullptr}; HardwareSerial *hw_serial_{nullptr};
struct LogLevelOverride { struct LogLevelOverride {

View file

@ -1,6 +1,6 @@
#include "esphome/core/log.h" #include "log.h"
#include "esphome/core/defines.h" #include "defines.h"
#include "esphome/core/helpers.h" #include "helpers.h"
#ifdef USE_LOGGER #ifdef USE_LOGGER
#include "esphome/components/logger/logger.h" #include "esphome/components/logger/logger.h"
@ -8,46 +8,40 @@
namespace esphome { namespace esphome {
int HOT esp_log_printf_(int level, const char *tag, const char *format, ...) { // NOLINT void HOT esp_log_printf_(int level, const char *tag, int line, const char *format, ...) { // NOLINT
va_list arg; va_list arg;
va_start(arg, format); va_start(arg, format);
int ret = esp_log_vprintf_(level, tag, format, arg); esp_log_vprintf_(level, tag, line, format, arg);
va_end(arg); va_end(arg);
return ret;
} }
#ifdef USE_STORE_LOG_STR_IN_FLASH #ifdef USE_STORE_LOG_STR_IN_FLASH
int HOT esp_log_printf_(int level, const char *tag, const __FlashStringHelper *format, ...) { void HOT esp_log_printf_(int level, const char *tag, int line, const __FlashStringHelper *format, ...) {
va_list arg; va_list arg;
va_start(arg, format); va_start(arg, format);
int ret = esp_log_vprintf_(level, tag, format, arg); esp_log_vprintf_(level, tag, line, format, arg);
va_end(arg); va_end(arg);
return ret;
return 0;
} }
#endif #endif
int HOT esp_log_vprintf_(int level, const char *tag, const char *format, va_list args) { // NOLINT void HOT esp_log_vprintf_(int level, const char *tag, int line, const char *format, va_list args) { // NOLINT
#ifdef USE_LOGGER #ifdef USE_LOGGER
auto *log = logger::global_logger; auto *log = logger::global_logger;
if (log == nullptr) if (log == nullptr)
return 0; return;
return log->log_vprintf_(level, tag, format, args); log->log_vprintf_(level, tag, line, format, args);
#else
return 0;
#endif #endif
} }
#ifdef USE_STORE_LOG_STR_IN_FLASH #ifdef USE_STORE_LOG_STR_IN_FLASH
int HOT esp_log_vprintf_(int level, const char *tag, const __FlashStringHelper *format, va_list args) { // NOLINT void HOT esp_log_vprintf_(int level, const char *tag, int line, const __FlashStringHelper *format,
va_list args) { // NOLINT
#ifdef USE_LOGGER #ifdef USE_LOGGER
auto *log = logger::global_logger; auto *log = logger::global_logger;
if (log == nullptr) if (log == nullptr)
return 0; return;
return log->log_vprintf_(level, tag, format, args); log->log_vprintf_(level, tag, line, format, args);
#else
return 0;
#endif #endif
} }
#endif #endif
@ -58,10 +52,9 @@ int HOT esp_idf_log_vprintf_(const char *format, va_list args) { // NOLINT
if (log == nullptr) if (log == nullptr)
return 0; return 0;
return log->log_vprintf_(log->get_global_log_level(), "", format, args); log->log_vprintf_(ESPHOME_LOG_LEVEL, "", 0, format, args);
#else
return 0;
#endif #endif
return 0;
} }
} // namespace esphome } // namespace esphome

View file

@ -20,9 +20,10 @@ namespace esphome {
#define ESPHOME_LOG_LEVEL_ERROR 1 #define ESPHOME_LOG_LEVEL_ERROR 1
#define ESPHOME_LOG_LEVEL_WARN 2 #define ESPHOME_LOG_LEVEL_WARN 2
#define ESPHOME_LOG_LEVEL_INFO 3 #define ESPHOME_LOG_LEVEL_INFO 3
#define ESPHOME_LOG_LEVEL_DEBUG 4 #define ESPHOME_LOG_LEVEL_CONFIG 4
#define ESPHOME_LOG_LEVEL_VERBOSE 5 #define ESPHOME_LOG_LEVEL_DEBUG 5
#define ESPHOME_LOG_LEVEL_VERY_VERBOSE 6 #define ESPHOME_LOG_LEVEL_VERBOSE 6
#define ESPHOME_LOG_LEVEL_VERY_VERBOSE 7
#ifndef ESPHOME_LOG_LEVEL #ifndef ESPHOME_LOG_LEVEL
#define ESPHOME_LOG_LEVEL ESPHOME_LOG_LEVEL_DEBUG #define ESPHOME_LOG_LEVEL ESPHOME_LOG_LEVEL_DEBUG
@ -43,38 +44,28 @@ namespace esphome {
#define ESPHOME_LOG_COLOR(COLOR) "\033[0;" COLOR "m" #define ESPHOME_LOG_COLOR(COLOR) "\033[0;" COLOR "m"
#define ESPHOME_LOG_BOLD(COLOR) "\033[1;" COLOR "m" #define ESPHOME_LOG_BOLD(COLOR) "\033[1;" COLOR "m"
#define ESPHOME_LOG_COLOR_E ESPHOME_LOG_BOLD(ESPHOME_LOG_COLOR_RED)
#define ESPHOME_LOG_COLOR_W ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_YELLOW)
#define ESPHOME_LOG_COLOR_I ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_GREEN)
#define ESPHOME_LOG_COLOR_C ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_MAGENTA)
#define ESPHOME_LOG_COLOR_D ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_CYAN)
#define ESPHOME_LOG_COLOR_V ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_GRAY)
#define ESPHOME_LOG_COLOR_VV ESPHOME_LOG_COLOR(ESPHOME_LOG_COLOR_WHITE)
#define ESPHOME_LOG_RESET_COLOR "\033[0m" #define ESPHOME_LOG_RESET_COLOR "\033[0m"
int esp_log_printf_(int level, const char *tag, const char *format, ...) // NOLINT void esp_log_printf_(int level, const char *tag, int line, const char *format, ...) // NOLINT
__attribute__((format(printf, 3, 4))); __attribute__((format(printf, 4, 5)));
#ifdef USE_STORE_LOG_STR_IN_FLASH #ifdef USE_STORE_LOG_STR_IN_FLASH
int esp_log_printf_(int level, const char *tag, const __FlashStringHelper *format, ...); void esp_log_printf_(int level, const char *tag, int line, const __FlashStringHelper *format, ...);
#endif #endif
int esp_log_vprintf_(int level, const char *tag, const char *format, va_list args); // NOLINT void esp_log_vprintf_(int level, const char *tag, int line, const char *format, va_list args); // NOLINT
#ifdef USE_STORE_LOG_STR_IN_FLASH #ifdef USE_STORE_LOG_STR_IN_FLASH
int esp_log_vprintf_(int level, const char *tag, const __FlashStringHelper *format, va_list args); void esp_log_vprintf_(int level, const char *tag, int line, const __FlashStringHelper *format, va_list args);
#endif #endif
int esp_idf_log_vprintf_(const char *format, va_list args); // NOLINT int esp_idf_log_vprintf_(const char *format, va_list args); // NOLINT
#ifdef USE_STORE_LOG_STR_IN_FLASH #ifdef USE_STORE_LOG_STR_IN_FLASH
#define ESPHOME_LOG_FORMAT(tag, letter, format) \ #define ESPHOME_LOG_FORMAT(format) F(format)
F(ESPHOME_LOG_COLOR_##letter "[" #letter "][%s:%03u]: " format ESPHOME_LOG_RESET_COLOR), tag, __LINE__
#else #else
#define ESPHOME_LOG_FORMAT(tag, letter, format) \ #define ESPHOME_LOG_FORMAT(format) format
ESPHOME_LOG_COLOR_##letter "[" #letter "][%s:%03u]: " format ESPHOME_LOG_RESET_COLOR, tag, __LINE__
#endif #endif
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE
#define esph_log_vv(tag, format, ...) \ #define esph_log_vv(tag, format, ...) \
esp_log_printf_(ESPHOME_LOG_LEVEL_VERY_VERBOSE, tag, ESPHOME_LOG_FORMAT(tag, VV, format), ##__VA_ARGS__) esp_log_printf_(ESPHOME_LOG_LEVEL_VERY_VERBOSE, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
#define ESPHOME_LOG_HAS_VERY_VERBOSE #define ESPHOME_LOG_HAS_VERY_VERBOSE
#else #else
@ -83,7 +74,7 @@ int esp_idf_log_vprintf_(const char *format, va_list args); // NOLINT
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
#define esph_log_v(tag, format, ...) \ #define esph_log_v(tag, format, ...) \
esp_log_printf_(ESPHOME_LOG_LEVEL_VERBOSE, tag, ESPHOME_LOG_FORMAT(tag, V, format), ##__VA_ARGS__) esp_log_printf_(ESPHOME_LOG_LEVEL_VERBOSE, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
#define ESPHOME_LOG_HAS_VERBOSE #define ESPHOME_LOG_HAS_VERBOSE
#else #else
@ -92,22 +83,20 @@ int esp_idf_log_vprintf_(const char *format, va_list args); // NOLINT
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_DEBUG #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_DEBUG
#define esph_log_d(tag, format, ...) \ #define esph_log_d(tag, format, ...) \
esp_log_printf_(ESPHOME_LOG_LEVEL_DEBUG, tag, ESPHOME_LOG_FORMAT(tag, D, format), ##__VA_ARGS__) esp_log_printf_(ESPHOME_LOG_LEVEL_DEBUG, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
#define esph_log_config(tag, format, ...) \ #define esph_log_config(tag, format, ...) \
esp_log_printf_(ESPHOME_LOG_LEVEL_DEBUG, tag, ESPHOME_LOG_FORMAT(tag, C, format), ##__VA_ARGS__) esp_log_printf_(ESPHOME_LOG_LEVEL_CONFIG, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
#define ESPHOME_LOG_HAS_DEBUG #define ESPHOME_LOG_HAS_DEBUG
#define ESPHOME_LOG_HAS_CONFIG #define ESPHOME_LOG_HAS_CONFIG
#else #else
#define esph_log_d(tag, format, ...) #define esph_log_d(tag, format, ...)
#define esph_log_config(tag, format, ...) #define esph_log_config(tag, format, ...)
#endif #endif
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_INFO #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_INFO
#define esph_log_i(tag, format, ...) \ #define esph_log_i(tag, format, ...) \
esp_log_printf_(ESPHOME_LOG_LEVEL_INFO, tag, ESPHOME_LOG_FORMAT(tag, I, format), ##__VA_ARGS__) esp_log_printf_(ESPHOME_LOG_LEVEL_INFO, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
#define ESPHOME_LOG_HAS_INFO #define ESPHOME_LOG_HAS_INFO
#else #else
@ -116,7 +105,7 @@ int esp_idf_log_vprintf_(const char *format, va_list args); // NOLINT
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_WARN #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_WARN
#define esph_log_w(tag, format, ...) \ #define esph_log_w(tag, format, ...) \
esp_log_printf_(ESPHOME_LOG_LEVEL_WARN, tag, ESPHOME_LOG_FORMAT(tag, W, format), ##__VA_ARGS__) esp_log_printf_(ESPHOME_LOG_LEVEL_WARN, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
#define ESPHOME_LOG_HAS_WARN #define ESPHOME_LOG_HAS_WARN
#else #else
@ -125,7 +114,7 @@ int esp_idf_log_vprintf_(const char *format, va_list args); // NOLINT
#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_ERROR #if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_ERROR
#define esph_log_e(tag, format, ...) \ #define esph_log_e(tag, format, ...) \
esp_log_printf_(ESPHOME_LOG_LEVEL_ERROR, tag, ESPHOME_LOG_FORMAT(tag, E, format), ##__VA_ARGS__) esp_log_printf_(ESPHOME_LOG_LEVEL_ERROR, tag, __LINE__, ESPHOME_LOG_FORMAT(format), ##__VA_ARGS__)
#define ESPHOME_LOG_HAS_ERROR #define ESPHOME_LOG_HAS_ERROR
#else #else