FOSS LIB 不是 HOW TODO:当文件太大或小时/天等变化时自动滚动的 OutputStream

发布于 2024-11-03 16:24:54 字数 543 浏览 3 评论 0原文

我想要一个 OutputStream 来执行 log4j 中 RollingXXXAppender 类中的许多功能。

是否有任何 FOSS 库支持简单 OutputStream 的这种智能。我宁愿代码不知道滚动过程并且不需要任何关于何时滚动的提示?理想情况下,滚动控制助手将被传递到工厂并隐藏在抽象的深处。

示例用例

  1. 自行关闭 -> file.txt
  2. 将原始文件重命名为某个备份 ->文件.txt -> file.001
  3. 重新创建一个空文件并继续写入 -> 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

  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 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白色秋天 2024-11-10 16:24:54

我认为您可以通过扩展 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文