Currently, the SD module save_json method uses the cursor position in the file to determine when to print the header rows. It checks if the cursor is at position 0 (aka beginning of file, or file empty). The problem with this is it makes it very difficult for users to add custom data to the beginning of a log file, because if they do, the SD module will never write the header rows to the log file and it just looks ugly.
I was running into this issue when working on SmartRock and couldn't see a clean way to get the desired functionality without modifying Loom. All this pull request does is, instead of checking if the file is empty, just check if the headers have been written yet or not using a local static variable. This makes it easy for people to write custom data to the beginning of a log file without having to try to come up with some clever work-around.
Currently, the SD module save_json method uses the cursor position in the file to determine when to print the header rows. It checks if the cursor is at position 0 (aka beginning of file, or file empty). The problem with this is it makes it very difficult for users to add custom data to the beginning of a log file, because if they do, the SD module will never write the header rows to the log file and it just looks ugly.
I was running into this issue when working on SmartRock and couldn't see a clean way to get the desired functionality without modifying Loom. All this pull request does is, instead of checking if the file is empty, just check if the headers have been written yet or not using a local static variable. This makes it easy for people to write custom data to the beginning of a log file without having to try to come up with some clever work-around.