开发者

FOSS LIB not HOW TODO: OutputStream that auto rolls when file gets too big or hour/day et change

开发者 https://www.devze.com 2023-03-01 16:18 出处:网络
Id like an OutputStream that performs many of the functions found in the RollingXXXAppender classes in log4j.

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

  1. closing itself -> file.txt
  2. renaming the original to some backup -> file.txt -> file.001
  3. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消