[logger] Move log level lookup tables to PROGMEM (#15003)

This commit is contained in:
J. Nick Koston
2026-03-22 12:32:08 -10:00
committed by GitHub
parent 9152f77cdd
commit 6caa9ee227

View File

@@ -1,5 +1,6 @@
#pragma once
#include "esphome/core/hal.h"
#include "esphome/core/helpers.h"
#include "esphome/core/log.h"
@@ -8,8 +9,8 @@ namespace esphome::logger {
// Maximum header size: 35 bytes fixed + 32 bytes tag + 16 bytes thread name = 83 bytes (45 byte safety margin)
static constexpr uint16_t MAX_HEADER_SIZE = 128;
// ANSI color code last digit (30-38 range, store only last digit to save RAM)
static constexpr char LOG_LEVEL_COLOR_DIGIT[] = {
// ANSI color code last digit (30-38 range, store only last digit to save RAM on ESP8266)
static const char LOG_LEVEL_COLOR_DIGIT[] PROGMEM = {
'\0', // NONE
'1', // ERROR (31 = red)
'3', // WARNING (33 = yellow)
@@ -20,7 +21,7 @@ static constexpr char LOG_LEVEL_COLOR_DIGIT[] = {
'8', // VERY_VERBOSE (38 = white)
};
static constexpr char LOG_LEVEL_LETTER_CHARS[] = {
static const char LOG_LEVEL_LETTER_CHARS[] PROGMEM = {
'\0', // NONE
'E', // ERROR
'W', // WARNING
@@ -64,7 +65,7 @@ struct LogBuffer {
*p++ = 'V'; // VERY_VERBOSE = "VV"
*p++ = 'V';
} else {
*p++ = LOG_LEVEL_LETTER_CHARS[level];
*p++ = static_cast<char>(progmem_read_byte(reinterpret_cast<const uint8_t *>(&LOG_LEVEL_LETTER_CHARS[level])));
}
}
*p++ = ']';
@@ -184,7 +185,7 @@ struct LogBuffer {
*p++ = (level == 1) ? '1' : '0'; // Only ERROR is bold
*p++ = ';';
*p++ = '3';
*p++ = LOG_LEVEL_COLOR_DIGIT[level];
*p++ = static_cast<char>(progmem_read_byte(reinterpret_cast<const uint8_t *>(&LOG_LEVEL_COLOR_DIGIT[level])));
*p++ = 'm';
}
// Copy string without null terminator, updates pointer in place