littlefs-project / littlefs

A little fail-safe filesystem designed for microcontrollers
BSD 3-Clause "New" or "Revised" License
5.09k stars 786 forks source link

Logging debug data for littlefs using littlefs #623

Open Magamanny opened 2 years ago

Magamanny commented 2 years ago

Hello, I am using the littlefs, and it is working great, currently I am directing all the debug data of 'LFSDEBUG()' macro to a serial port. Now I was thing of also wiring that data to a log file. The issue is that the log file will be written by using littlefs(same IC and fs instance). Thus the the logging function can stuck in a recursive loop(I think.). Is it possible to log littlefs, debug, trace, warn, error using the same littlefs instance? Can I mount two separate littlefs in a single IC(Like diving the ic in tow groups(even bank, odd bank))? Is it even useful to see the log? Hope this make sense.

geky commented 2 years ago

Hi @Magamanny thanks for creating an issue and sorry for the late response.

That's quite a funny paradox you have there.

Writing the logs to littlefs itself is reasonable, but you should make sure that your LFS_DEBUG/WARN/ERROR implementations set a flag preventing recursive logging (I haven't tested this code):

bool lfs_in_log = false;
#define LFS_DEBUG(x) do {
    if (!lfs_in_log) {
        lfs_in_log = true;
        printf(x);
        lfs_in_log = false;
    }
} while (0)

Can I mount two separate littlefs in a single IC(Like diving the ic in tow groups(even bank, odd bank))?

You could as long as your block device implementation can separate write/reads to both. You could also create a block device implementation that combines both and mount one littlefs image that is evenly distributed across both banks. It depends on what your goal is.

Is it even useful to see the log?

This sort of depends on what you're planning to do when an error happens. You could look at the log and if you see a large number of bad-block messages that would hint that the storage was near its end-of-life.

Linux, etc, keep filesystem logs on the filesystem, but compared to microcontrollers, those systems are more interactive with more effort going into recovering failing disks.

I'm not sure this question has a clear answer.

Hopefully this info helps.