Page 1 of 1

Redirecting ESP Log output to file and back to USB serial

Posted: Sun Jan 15, 2023 5:47 pm
by jmadsenee
I am building a system that will have no USB serial connection most of the time and I want to re-direct stdout to a file on an SD card to store all of the logging messages. I am using:

Code: Select all

freopen(FileMonitorLog, "a", stdout);
to redirect stdout. Works great. Now at some point a USB connection may become available and I want to redirect stdout back to the USB serial port. What is the proper filename and mode to put into

Code: Select all

FILE *freopen(const char *filename, const char *mode, FILE *stream)
?

Thanks so much!