Saving debug log

ndjurov
Posts: 65
Joined: Wed Mar 25, 2020 11:34 pm

Saving debug log

Postby ndjurov » Fri Feb 25, 2022 11:52 pm

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.

ndjurov
Posts: 65
Joined: Wed Mar 25, 2020 11:34 pm

Re: Saving debug log

Postby ndjurov » Mon Feb 28, 2022 1:18 am

Just to ask if there are any suggestions.
Thank you.

ESP_Sprite
Posts: 9715
Joined: Thu Nov 26, 2015 4:08 am

Re: Saving debug log

Postby ESP_Sprite » Tue Mar 01, 2022 1:21 am

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.

ndjurov
Posts: 65
Joined: Wed Mar 25, 2020 11:34 pm

Re: Saving debug log

Postby ndjurov » Tue Mar 01, 2022 7:33 am

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.

Who is online

Users browsing this forum: No registered users and 305 guests