Describe the bug
The logging system (logPrint) is currently used in setup() before the log buffer (logBuffer) is allocated via initLogger() (or ps_malloc). This happens in two places:
- When
psramInit() fails, the code calls logPrint(F("[E] ...")) but logBuffer is still nullptr.
- When
LittleFS.begin() fails (if placed before PSRAM init), logPrint is called before PSRAM allocation.
Although logPrint has a if (!logBuffer) return; guard to prevent crashes, the log messages are silently dropped without any trace in the ring buffer (though they still go to Serial). This makes debugging remote/Web-based log viewing unreliable when early initialization fails.
Proposed Fix
I'm currently working on a refactor to extract the logger into a dedicated module (logger.h / logger.cpp) with the following changes:
- Add
bool initLogger() that returns allocation status.
- Restore the correct initialization order in
setup():
Serial → LittleFS → PSRAM → initLogger() → then use logPrint.
- Use
goto for unified error handling in setup() to avoid deep nesting.
- Expose
const char* getLogBuffer() for Web /log endpoint (instead of exposing raw global pointer).
Status
I have already started working on this in my local branch. I will open a PR referencing this issue within a few days. If you (maintainer) have any preference on the error-handling style (e.g., keep while(1) halt vs. LED blink), please let me know.
Affected Version
Current main branch (as of [date]).
Describe the bug
The logging system (
logPrint) is currently used insetup()before the log buffer (logBuffer) is allocated viainitLogger()(orps_malloc). This happens in two places:psramInit()fails, the code callslogPrint(F("[E] ..."))butlogBufferis stillnullptr.LittleFS.begin()fails (if placed before PSRAM init),logPrintis called before PSRAM allocation.Although
logPrinthas aif (!logBuffer) return;guard to prevent crashes, the log messages are silently dropped without any trace in the ring buffer (though they still go to Serial). This makes debugging remote/Web-based log viewing unreliable when early initialization fails.Proposed Fix
I'm currently working on a refactor to extract the logger into a dedicated module (
logger.h/logger.cpp) with the following changes:bool initLogger()that returns allocation status.setup():Serial→LittleFS→PSRAM→initLogger()→ then uselogPrint.gotofor unified error handling insetup()to avoid deep nesting.const char* getLogBuffer()for Web/logendpoint (instead of exposing raw global pointer).Status
I have already started working on this in my local branch. I will open a PR referencing this issue within a few days. If you (maintainer) have any preference on the error-handling style (e.g., keep
while(1)halt vs. LED blink), please let me know.Affected Version
Current
mainbranch (as of [date]).