Missing data when logging continuously on eMMC

Here is a recap of the comments to close the question:

  • Constant writing to eMMC with such a rate will worn out flash very quickly.
  • There is no apparent problem in the way the code writes to file. Maybe there is some internal buffers overrun while OS is busy doing some household tasks.
  • For large amount of data you can use mini HDD like this one - https://www.amazon.com/Toshiba-MK2533GSG-Small-Factor-Drive/dp/B00JRJKFJQ . You can connect it to your system using USB - SATA adapter either external one like this - https://www.amazon.com/Micro-SATA-1-8-Adapter-Cable/dp/B0037JACXG or you can embed required IC to your carrier board. If shock and/or vibration condition doesn’t allow to use mechnical HDD you can use flash memory device like eMMC or SSD . However to get appropriate life time its size should be significantly bigger than required log size. For your case (4GB) it should be not less than 64Gb or so. To do a proper size calculation please follow eMMC (Linux) | Toradex Developer Center

Thanks to Toradex staff for their support on this topic.