I think ash is wanting to drop old log lines and add new ones to a simple textual log file.
The short answer is typically 'no, there is not a simple way to do this', because a files is a simple linear sequence of byte, much like a hunk of memory, only on secondary storage. So, just as with a hunk of memory, to do it you would need to copy all the stuff down over what you are dropping, and then append what is the new record. To cope with that limitation, two approaches are sometmes taken, either:
a ) use some storage that is structured, like a database, then the record ordering is logical rather than physical, and you can avoid moving the stuff to effectively drop the oldest and add the newest. You could use something like sqlite etc on desktop if you really wanted to do that, but this is embedded so that approach is not feasible.
b ) use a log rotation scheme. basically you write to a log file until it reaches a certain size, then open a new one, continuing from there. At the same time and just prior to opening the new file. you delete the oldest one. Usually you have some parameters such as 'how many old logs to keep' and 'how big will a log get before you move on to a new one'. If you think about it, this is effectively the same as approach 'a', except that you are using the filesystem directory as your quasi-database, and you are working with groups of log lines (in a file) instead of individual ones.
-daveGo to the full post