This is a story on adding a line of text to a log file.
It is not good that the log file grows infinitely. Since the outdated records are normally of no use anyway, the file can be made circular -- whether of limited line numbers or limited size. The first better addresses the obsolescence issue while the latter better controls the storage resource and thus is of more preference in the embedded real-time systems, where resources are preallocated.
Here, EOL, NL, LF, CRLF and '\n' all are the same newline character.
When created, it is filled with arbitrary characters. The first line of fixed size keeps a pointer to begin and end of the buffer. Reader reads records from the start; writer appends lines to the end. Written a message, the writer moves the writing pointer to the end of just-written line and reading position is shifted beyond the end of overwritten record if writer crosses the reader position.
If the message is longer than the file, it is written at the file start and is ended by ellipsis ... char. Or log exception is to be thrown?
The lines can be read by line readers. Reading the last line wraps to the file beginning if no EOL is present at the EOF.