I created a simple logger that, well, writes all the values to a text file. I use std::ofstream, but there is a problem - when the program does not close the file (call std::ofstream::close()) for any reason (for example, a failure), the created log is actually empty (size 0). And since the magazine is most useful in exceptional situations (when something goes wrong) - you see the problem.
Is there a way to protect my journal from this? I could try to close the file after writing each pair of lines and using append, but this still does not protect me from the situation when the program crashes out of the system in the middle of logging / before closing the file. Is there any solution, or am I just doomed?
source
share