I would like to reroute debug messages (those that normally go out to UART0 and are captured by a host terminal application on the other side) to a local SPIFFS file.
My understanding is that there are at least two ways of doing it:
Either by using printf() in the code and replacing stdout file descriptor with a spiffs file one,
Or by using IDF's ESP_LOGx() macros and using esp_log_set_vprintf() to replace vprintf() by another function that may finally use something like vfprintf to put the log data into the flash based log file.
One advantage of using ESP_LOGx() macros is that a module TAG is attached to a log line, but his is something that can easily be achieved creating a printf() based macro.
1. Please correct me if I'm wrong about this.
2. Which one of these two methods is better in terms of CPU and memory resources (time, stack space, heap use etc.).
Thank you.
Saving debug log
Re: Saving debug log
Just to ask if there are any suggestions.
Thank you.
Thank you.
-
- Posts: 9715
- Joined: Thu Nov 26, 2015 4:08 am
Re: Saving debug log
You can do both, I don't think there's much of a difference in resource use. Note that by redirecting printf, you'll also capture the ESP_LOG* output.
Re: Saving debug log
Thank you very much.
In the end, instead of using file descriptors and dup(), or freopen(), I decided to use fprintf() instead of printf() everywhere in the code and just to use either stdout or to a log file pointer as the parameter, flushing the buffers before switching.
Appears to be safe and simple.
In the end, instead of using file descriptors and dup(), or freopen(), I decided to use fprintf() instead of printf() everywhere in the code and just to use either stdout or to a log file pointer as the parameter, flushing the buffers before switching.
Appears to be safe and simple.
Who is online
Users browsing this forum: No registered users and 305 guests