mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
ESP32: Conditionally log on services to avoid OOM crashes (#1098)
Also removed new line formatting tidy as it requires a bit of memory which might not be available. * Use suitably scoped char for log newline stripping * fix formatting * Better fix for OOM logging crash * Limit to ESP32 only * format changes
This commit is contained in:
parent
82d5d50d61
commit
148f5d9418
2 changed files with 10 additions and 10 deletions
|
@ -103,7 +103,17 @@ void HOT Logger::log_message_(int level, const char *tag, int offset) {
|
|||
const char *msg = this->tx_buffer_ + offset;
|
||||
if (this->baud_rate_ > 0)
|
||||
this->hw_serial_->println(msg);
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
// Suppress network-logging if memory constrained, but still log to serial
|
||||
// ports. In some configurations (eg BLE enabled) there may be some transient
|
||||
// memory exhaustion, and trying to log when OOM can lead to a crash. Skipping
|
||||
// here usually allows the stack to recover instead.
|
||||
// See issue #1234 for analysis.
|
||||
if (xPortGetFreeHeapSize() > 2048)
|
||||
this->log_callback_.call(level, tag, msg);
|
||||
#else
|
||||
this->log_callback_.call(level, tag, msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
Logger::Logger(uint32_t baud_rate, size_t tx_buffer_size, UARTSelection uart)
|
||||
|
|
|
@ -53,16 +53,6 @@ int HOT esp_idf_log_vprintf_(const char *format, va_list args) { // NOLINT
|
|||
if (log == nullptr)
|
||||
return 0;
|
||||
|
||||
size_t len = strlen(format);
|
||||
if (format[len - 1] == '\n') {
|
||||
// Remove trailing newline from format
|
||||
// Use locally stored
|
||||
static std::string FORMAT_COPY;
|
||||
FORMAT_COPY.clear();
|
||||
FORMAT_COPY.insert(0, format, len - 1);
|
||||
format = FORMAT_COPY.c_str();
|
||||
}
|
||||
|
||||
log->log_vprintf_(ESPHOME_LOG_LEVEL, "esp-idf", 0, format, args);
|
||||
#endif
|
||||
return 0;
|
||||
|
|
Loading…
Reference in a new issue