Id like an OutputStream that performs many of the functions found in the RollingXXXAppender classes in log4j.
Are there any FOSS libraries that support this sort of smarts for a simple OutputStream. Id rather the code not be aware of the rolling process and not require any hints as to when to roll ? Ideally the rolling control helpers would be passed to the factory and hidden deep inside the abstraction.
SAMPLE USE CASE
- closing itself -> file.txt
- renaming the original to some backup -> file.txt -> file.001
- recreating an empty file and continue writing -> file.txt
This sort of functionality works best for any system that requires the creation of really large files such as logging.
POTENTIONAL PROBLEMS
- it should have some smarts and not r开发者_开发问答oll in the middle of a line write. Probably the best solution to this is to have the roll tests to be performed before/after a write rather than in the middle.
RE: TIPS ON HOW TO WRITE MY OWN..
I dont want to write my own, i know how to - which is why i mentioned RollingXXXAppender. I would rather leverage the effort of a preexisting library.
I think you can easily implement this by extending a FileOutputStream. One thing to bear in mind, though, is that this approach only makes sense if you are willing to keep the file open -instead of opening and closing it in each write ; which in turn only makes sense if the writing to this log file is centralized.
精彩评论