[log] Strengthen comment about no null checks on hot path

This commit is contained in:
J. Nick Koston
2026-03-05 21:49:26 -10:00
parent 8a2514a9c9
commit 8d36935083
+7 -3
View File
@@ -8,9 +8,13 @@
namespace esphome {
// No null check on global_logger — Logger::pre_setup() sets global_logger
// before any other component is created in the generated setup() function,
// so it is guaranteed to be valid by the time any log function is invoked.
// IMPORTANT: Do not add null checks on global_logger here.
// These functions are the hot path for ALL logging across the entire firmware,
// so every instruction matters. Logger::pre_setup() sets global_logger before
// any other component is created in the generated setup() function, so it is
// guaranteed to be valid by the time any log function is invoked. This invariant
// is enforced by codegen ordering and tested in
// tests/component_tests/logger/test_logger.py.
void HOT esp_log_printf_(int level, const char *tag, int line, const char *format, ...) { // NOLINT
#ifdef USE_LOGGER
va_list arg;