Skip to content

fix: logger initialization order causes silent log loss on PSRAM init failure #25

Description

@Kerlynx

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:

  1. When psramInit() fails, the code calls logPrint(F("[E] ...")) but logBuffer is still nullptr.
  2. 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():
    SerialLittleFSPSRAMinitLogger() → 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]).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions