FOSS LIB 不是 HOW TODO:当文件太大或小时/天等变化时自动滚动的 OutputStream
我想要一个 OutputStream 来执行 log4j 中 RollingXXXAppender 类中的许多功能。
是否有任何 FOSS 库支持简单 OutputStream 的这种智能。我宁愿代码不知道滚动过程并且不需要任何关于何时滚动的提示?理想情况下,滚动控制助手将被传递到工厂并隐藏在抽象的深处。
示例用例
- 自行关闭 -> file.txt
- 将原始文件重命名为某个备份 ->文件.txt -> file.001
- 重新创建一个空文件并继续写入 -> file.txt
这种功能最适合任何需要创建非常大的文件(例如日志记录)的系统。
潜在问题
- 它应该有一些智能,并且不会在一行写入的中间滚动。对此最好的解决方案可能是在写入之前/之后执行滚动测试,而不是在中间执行。
回复:关于如何编写自己的提示..
我不想编写自己的,我知道如何 - 这就是我提到 RollingXXXAppender 的原因。我宁愿利用现有图书馆的努力。
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 roll 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可以通过扩展 FileOutputStream 轻松实现此目的。但要记住的一件事是,只有当您愿意保持文件打开状态(而不是在每次写入时打开和关闭它)时,这种方法才有意义;反过来,只有集中写入此日志文件才有意义。
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.