esp_log_set_vprintf to write to SPIFFS file

kh13824
Posts: 10
Joined: Tue Oct 18, 2022 6:01 pm

esp_log_set_vprintf to write to SPIFFS file

Postby kh13824 » Thu Jul 13, 2023 3:53 pm

Hello,

I am attempting to write ESP_LOGE messages to a SPIFFS txt file with the use of esp_log_set_vprintf. I am having some success in writing to a my file but for some reason when reading the file my log messages are duplicated
spiffs_double_write.png
spiffs_double_write.png (26.45 KiB) Viewed 1090 times
I am writing a total of 5 error log messages and I have a vsprintf function and I'm using fputs(str_buffer) into my file. I am using standard fopen & fclose functions and using the "a" flag with fopen to append to the existing log file in SPIFFS. My log messages always duplicates to 10 log messages when using the "a" flag but when I use the "w" flag I have no issues with writing 5 log messages to SPIFFS. I would like to keep using append so I do not overwrite my the file every time I write a log message to a file. Has anybody tried using the esp_log_set_vprintf before and encountered this issue? Any help would be appreciated.

RandomInternetGuy
Posts: 52
Joined: Fri Aug 11, 2023 4:56 am

Re: esp_log_set_vprintf to write to SPIFFS file

Postby RandomInternetGuy » Sat Aug 12, 2023 6:01 am

The SPIFFS filesystem isn't really very POSIX-like at all. You can't just open(..., "a") and go. There's a special method entry point for that.

appendFile(SPIFFS, "/hello.txt", "World!\r\n");

See more at https://github.com/espressif/arduino-es ... st.ino#L72

Supposedly littlefs is less wretched. It's on my short list to move my project to that.

Who is online

Users browsing this forum: No registered users and 104 guests