obstacles and best practise to redirect error loggig to a SD card file?

RalphD
Posts: 103
Joined: Thu Nov 25, 2021 9:02 pm

obstacles and best practise to redirect error loggig to a SD card file?

Postby RalphD » Thu Feb 16, 2023 1:28 pm

We have an application using the ESP32 S2 in production and are unable to log an issue we have that the ESP32 S2 does not reconnect occasionally. As in production use we require to access the logs remotely.

The system has a SD card and logs could be written on it. However, this would require that the log file will be properly closed after writing. What are the options by avoiding to change the IDF core?

Any hint appreciated, thanks

MicroController
Posts: 1710
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: obstacles and best practise to redirect error loggig to a SD card file?

Postby MicroController » Thu Feb 16, 2023 4:22 pm

You could redirect IDF's logging to a custom function (via esp_log_set_vprintf(...)), and that function can do whatever is necessary to dump the log message to wherever.

You can of course call your own log-file writing function directly at only those specific points where you want it, instead of pushing all ESP_LOGx log messages through.

Using FatFs, I found that it is actually not necessary (or beneficial) to close a file just to get it into a consistent persistent state: FatFs's f_sync(...) will do that without actually closing the file, so that you do not have to costly re-open it everytime to continue writing. However, flushing to SD may still be too "expensive" (possibly tens of milliseconds!) to do for every log event.

RalphD
Posts: 103
Joined: Thu Nov 25, 2021 9:02 pm

Re: obstacles and best practise to redirect error loggig to a SD card file?

Postby RalphD » Thu Feb 16, 2023 4:46 pm

Thanks @MicroController looks very strait forward. Great hint

Who is online

Users browsing this forum: Google [Bot] and 67 guests