[logger] Make boot log buffer log level configurable

(cherry picked from commit 7f532b3021999bb75551368ca13966b729a89011)
This commit is contained in:
Omni Flux
2026-10-13 10:22:18 -10:00
committed by J. Nick Koston
parent 4b029993a4
commit 9a353cc3e2
4 changed files with 10 additions and 4 deletions
+6 -1
View File
@@ -106,6 +106,7 @@ USB_CDC = "USB_CDC"
DEFAULT = "DEFAULT"
CONF_BOOT_LOG_BUFFER_SIZE = "boot_log_buffer_size"
CONF_BOOT_LOG_LEVEL = "boot_log_level"
CONF_INITIAL_LEVEL = "initial_level"
CONF_LOGGER_ID = "logger_id"
CONF_ESP8266_STORE_LOG_STRINGS_IN_FLASH = "esp8266_store_log_strings_in_flash"
@@ -273,6 +274,7 @@ CONFIG_SCHEMA = cv.All(
cv.int_range(min=512, max=16384),
),
),
cv.Optional(CONF_BOOT_LOG_LEVEL, default="WARN"): is_log_level,
cv.SplitDefault(
CONF_TASK_LOG_BUFFER_SIZE,
esp32=768, # Default: 768 bytes (~5-6 messages with 70-byte text plus thread names)
@@ -385,11 +387,14 @@ async def to_code(config: ConfigType) -> None:
if task_log_buffer_size > 0:
cg.add_define("USE_ESPHOME_TASK_LOG_BUFFER")
cg.add_define("ESPHOME_TASK_LOG_BUFFER_SIZE", task_log_buffer_size)
# Boot log buffer captures early WARN/ERROR lines for later replay
# Boot log buffer captures early lines for later replay
# (logger.replay_boot_logs action). Buffer is a direct member of Logger.
if (boot_log_buffer_size := config[CONF_BOOT_LOG_BUFFER_SIZE]) > 0:
cg.add_define("USE_LOGGER_BOOT_LOG_BUFFER")
cg.add_define("ESPHOME_LOGGER_BOOT_LOG_BUFFER_SIZE", boot_log_buffer_size)
cg.add_build_flag(
f"-DESPHOME_LOGGER_BOOT_LOG_LEVEL={LOG_LEVELS[config[CONF_BOOT_LOG_LEVEL]]}"
)
log = cg.new_Pvariable(
config[CONF_ID],
baud_rate,
+1 -1
View File
@@ -209,7 +209,7 @@ void Logger::process_messages_() {
static constexpr uint16_t BOOT_LOG_RECORD_HEADER_SIZE = 2 + 1 + 4 + sizeof(const char *);
void Logger::boot_log_capture_(uint8_t level, const char *tag, const LogBuffer &buf) {
if (this->boot_log_done_ || level > ESPHOME_LOG_LEVEL_WARN || level == ESPHOME_LOG_LEVEL_NONE)
if (this->boot_log_done_ || level > ESPHOME_LOGGER_BOOT_LOG_LEVEL || level == ESPHOME_LOG_LEVEL_NONE)
return;
// Strip the leading ANSI color prefix and trailing reset; the replay adds its own around the stamp.
const char *text = buf.data;
+2 -2
View File
@@ -179,7 +179,7 @@ class Logger final : public Component {
#endif
uint8_t get_log_level() { return this->current_level_; }
/// Re-emit WARN/ERROR messages captured during boot through the normal log
/// Re-emit messages captured during boot through the normal log
/// dispatch so connected listeners (API, MQTT, ...) can see them. Stops
/// further capture; safe to call multiple times. Warns when the logger was
/// built without 'boot_log_buffer_size'.
@@ -396,7 +396,7 @@ class Logger final : public Component {
// Large buffers placed last to keep frequently-accessed member offsets small
char tx_buffer_[ESPHOME_LOGGER_TX_BUFFER_SIZE + 1]; // +1 for null terminator
#ifdef USE_LOGGER_BOOT_LOG_BUFFER
// Sequential records of early WARN/ERROR lines: u16 text_len | u8 level | u32 millis | const char *tag | text
// Sequential records of early lines: u16 text_len | u8 level | u32 millis | const char *tag | text
char boot_log_buffer_[ESPHOME_LOGGER_BOOT_LOG_BUFFER_SIZE];
#endif
#ifdef USE_ESPHOME_TASK_LOG_BUFFER
+1
View File
@@ -41,6 +41,7 @@
#define ESPHOME_LOG_MAX_LISTENERS 8
#define USE_LOGGER_BOOT_LOG_BUFFER
#define ESPHOME_LOGGER_BOOT_LOG_BUFFER_SIZE 4096
#define ESPHOME_LOGGER_BOOT_LOG_LEVEL ESPHOME_LOG_LEVEL_WARN
// Feature flags
#define USE_ALARM_CONTROL_PANEL