• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Limit log file size, with 'scrolling'.

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic