From 09d8e38438ec5dad5a801abf5650ef0bf6b76221 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 19 Mar 2026 10:37:16 -1000 Subject: [PATCH] [logger] Move set_log_level to early init phase Ensures initial log level filtering is active before platform code runs, preventing VV spam when initial_level < VERY_VERBOSE. --- esphome/components/logger/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/esphome/components/logger/__init__.py b/esphome/components/logger/__init__.py index f5fc284294..a5601e6a8f 100644 --- a/esphome/components/logger/__init__.py +++ b/esphome/components/logger/__init__.py @@ -350,6 +350,8 @@ async def to_code(config: ConfigType) -> None: # pre_setup() sets global_logger and must run before any other code # that may call ESP_LOG* (e.g. setup_preferences contains ESP_LOGVV). cg.add(log.pre_setup()) + initial_level = LOG_LEVELS[config.get(CONF_INITIAL_LEVEL, level)] + cg.add(log.set_log_level(initial_level)) # Schedule the rest of logger setup at DIAGNOSTICS priority, after # Application is constructed (CORE priority) but before most components. @@ -361,7 +363,6 @@ async def _late_logger_init(config: ConfigType) -> None: """Finish logger setup after Application is constructed.""" log = await cg.get_variable(config[CONF_ID]) level = config[CONF_LEVEL] - initial_level = LOG_LEVELS[config.get(CONF_INITIAL_LEVEL, level)] baud_rate: int = config[CONF_BAUD_RATE] if CORE.is_esp32 or CORE.is_libretiny or CORE.is_nrf52: task_log_buffer_size = config[CONF_TASK_LOG_BUFFER_SIZE] @@ -375,8 +376,6 @@ async def _late_logger_init(config: ConfigType) -> None: cg.add_define("USE_ESPHOME_TASK_LOG_BUFFER") cg.add(log.init_log_buffer(64)) # Fixed 64 slots for host - cg.add(log.set_log_level(initial_level)) - # Enable runtime tag levels if logs are configured or explicitly enabled logs_config = config[CONF_LOGS] if logs_config or config[CONF_RUNTIME_TAG_LEVELS]: