From b3683d518f062fa377eaccc8e526f491c66d9198 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 29 Jan 2026 08:29:03 -0600 Subject: [PATCH 1/3] Fix ESP8266 logging to not require global Serial object --- src/AsyncWebServerLogging.h | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/AsyncWebServerLogging.h b/src/AsyncWebServerLogging.h index 21b75824..e6cb608c 100644 --- a/src/AsyncWebServerLogging.h +++ b/src/AsyncWebServerLogging.h @@ -81,9 +81,12 @@ /** * ESP8266 specific configurations + * Uses ets_printf to avoid dependency on global Serial object. + * Format strings are stored in PROGMEM and copied to a stack buffer. */ #elif defined(ESP8266) #include +#include // define log levels #define ASYNC_WS_LOG_NONE 0 /*!< No log output */ #define ASYNC_WS_LOG_ERROR 1 /*!< Critical errors, software module can not recover on its own */ @@ -96,33 +99,43 @@ #ifndef ASYNCWEBSERVER_LOG_LEVEL #define ASYNCWEBSERVER_LOG_LEVEL ASYNC_WS_LOG_INFO #endif +// helper macro to copy PROGMEM format string to stack and call ets_printf +// level is a char literal ('E', 'W', etc.) to avoid RAM usage from string literals +#define _ASYNC_WS_LOG(level, format, ...) \ + do { \ + static const char __fmt[] PROGMEM = "%c async_ws %d: " format "\n"; \ + char __buf[64]; \ + strncpy_P(__buf, __fmt, sizeof(__buf) - 1); \ + __buf[sizeof(__buf) - 1] = '\0'; \ + ets_printf(__buf, level, __LINE__, ##__VA_ARGS__); \ + } while (0) // error #if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_ERROR -#define async_ws_log_e(format, ...) Serial.printf_P(PSTR("E async_ws %d: " format "\n"), __LINE__, ##__VA_ARGS__) +#define async_ws_log_e(format, ...) _ASYNC_WS_LOG('E', format, ##__VA_ARGS__) #else #define async_ws_log_e(format, ...) #endif // warn #if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_WARN -#define async_ws_log_w(format, ...) Serial.printf_P(PSTR("W async_ws %d: " format "\n"), __LINE__, ##__VA_ARGS__) +#define async_ws_log_w(format, ...) _ASYNC_WS_LOG('W', format, ##__VA_ARGS__) #else #define async_ws_log_w(format, ...) #endif // info #if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_INFO -#define async_ws_log_i(format, ...) Serial.printf_P(PSTR("I async_ws %d: " format "\n"), __LINE__, ##__VA_ARGS__) +#define async_ws_log_i(format, ...) _ASYNC_WS_LOG('I', format, ##__VA_ARGS__) #else #define async_ws_log_i(format, ...) #endif // debug #if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_DEBUG -#define async_ws_log_d(format, ...) Serial.printf_P(PSTR("D async_ws %d: " format "\n"), __LINE__, ##__VA_ARGS__) +#define async_ws_log_d(format, ...) _ASYNC_WS_LOG('D', format, ##__VA_ARGS__) #else #define async_ws_log_d(format, ...) #endif // verbose #if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_VERBOSE -#define async_ws_log_v(format, ...) Serial.printf_P(PSTR("V async_ws %d: " format "\n"), __LINE__, ##__VA_ARGS__) +#define async_ws_log_v(format, ...) _ASYNC_WS_LOG('V', format, ##__VA_ARGS__) #else #define async_ws_log_v(format, ...) #endif From f120013f0fbe0cf053a805c666c0d198ecc49778 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Thu, 29 Jan 2026 17:22:12 +0000 Subject: [PATCH 2/3] ci(pre-commit): Apply automatic fixes --- src/AsyncWebServerLogging.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/AsyncWebServerLogging.h b/src/AsyncWebServerLogging.h index e6cb608c..5715e45a 100644 --- a/src/AsyncWebServerLogging.h +++ b/src/AsyncWebServerLogging.h @@ -101,13 +101,13 @@ #endif // helper macro to copy PROGMEM format string to stack and call ets_printf // level is a char literal ('E', 'W', etc.) to avoid RAM usage from string literals -#define _ASYNC_WS_LOG(level, format, ...) \ - do { \ +#define _ASYNC_WS_LOG(level, format, ...) \ + do { \ static const char __fmt[] PROGMEM = "%c async_ws %d: " format "\n"; \ - char __buf[64]; \ - strncpy_P(__buf, __fmt, sizeof(__buf) - 1); \ - __buf[sizeof(__buf) - 1] = '\0'; \ - ets_printf(__buf, level, __LINE__, ##__VA_ARGS__); \ + char __buf[64]; \ + strncpy_P(__buf, __fmt, sizeof(__buf) - 1); \ + __buf[sizeof(__buf) - 1] = '\0'; \ + ets_printf(__buf, level, __LINE__, ##__VA_ARGS__); \ } while (0) // error #if ASYNCWEBSERVER_LOG_LEVEL >= ASYNC_WS_LOG_ERROR From e3801963a7730d1ccb57c551ac89ea66864ee9cf Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 29 Jan 2026 14:41:13 -0600 Subject: [PATCH 3/3] use sizeof --- src/AsyncWebServerLogging.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/AsyncWebServerLogging.h b/src/AsyncWebServerLogging.h index 5715e45a..f550fd9e 100644 --- a/src/AsyncWebServerLogging.h +++ b/src/AsyncWebServerLogging.h @@ -104,9 +104,8 @@ #define _ASYNC_WS_LOG(level, format, ...) \ do { \ static const char __fmt[] PROGMEM = "%c async_ws %d: " format "\n"; \ - char __buf[64]; \ - strncpy_P(__buf, __fmt, sizeof(__buf) - 1); \ - __buf[sizeof(__buf) - 1] = '\0'; \ + char __buf[sizeof(__fmt)]; \ + strcpy_P(__buf, __fmt); \ ets_printf(__buf, level, __LINE__, ##__VA_ARGS__); \ } while (0) // error