• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Limit log file size, with 'scrolling'.

 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
I am creating a log file which grows very quickly to a huge size. I would like to fix the size of the file to say 1MB and if there is new data, 'scroll' the old data at the top of the file off and append new data at the end. (Circular file).
Any ideas on how to implement this?
Right now i am using a FileOutputStream with append TRUE to append to the log file.
Any help would be appreciated!
 
Carl Trusiak
Sheriff
Posts: 3340
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, once a line is written to a file, the only way to remove it is to completely rewrite that file or over write that data. Another concept you can use is to implement your file as a random access file. Once you reach the max number of items in your file, you start writing them again at the start of the file. This presents a problem when you try and read or display the contents but, I think you can find a way to write a log display program that can get around the limitation of this approach.
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
Thanks Carl,
Yeah, i was thinking of going the Random Access File route. Rewriting would have to be done at the top of the file and not 'scrolled' as i had first thought so the display would definitely need some work.
Unless i tried to 'scroll' backwards so the stales log would be at the bottom of the file and the top of the file would have the latest log data. This would mean manipulating the File Pointer somehow and restricting the file size....
..anyway, thanks for your input!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic