esphome/esphome/core/log.cpp
Otto Winter 904a0b26ea
Make logger string memory usage more efficient (#641)
* Make logger string storing more efficient

* Lint
2019-06-16 19:14:24 +02:00

60 lines
1.5 KiB
C++

#include "log.h"
#include "defines.h"
#include "helpers.h"
#ifdef USE_LOGGER
#include "esphome/components/logger/logger.h"
#endif
namespace esphome {
void HOT esp_log_printf_(int level, const char *tag, int line, const char *format, ...) { // NOLINT
va_list arg;
va_start(arg, format);
esp_log_vprintf_(level, tag, line, format, arg);
va_end(arg);
}
#ifdef USE_STORE_LOG_STR_IN_FLASH
void HOT esp_log_printf_(int level, const char *tag, int line, const __FlashStringHelper *format, ...) {
va_list arg;
va_start(arg, format);
esp_log_vprintf_(level, tag, line, format, arg);
va_end(arg);
}
#endif
void HOT esp_log_vprintf_(int level, const char *tag, int line, const char *format, va_list args) { // NOLINT
#ifdef USE_LOGGER
auto *log = logger::global_logger;
if (log == nullptr)
return;
log->log_vprintf_(level, tag, line, format, args);
#endif
}
#ifdef USE_STORE_LOG_STR_IN_FLASH
void HOT esp_log_vprintf_(int level, const char *tag, int line, const __FlashStringHelper *format,
va_list args) { // NOLINT
#ifdef USE_LOGGER
auto *log = logger::global_logger;
if (log == nullptr)
return;
log->log_vprintf_(level, tag, line, format, args);
#endif
}
#endif
int HOT esp_idf_log_vprintf_(const char *format, va_list args) { // NOLINT
#ifdef USE_LOGGER
auto *log = logger::global_logger;
if (log == nullptr)
return 0;
log->log_vprintf_(ESPHOME_LOG_LEVEL, "", 0, format, args);
#endif
return 0;
}
} // namespace esphome