压缩 Log4j 文件
是否可以压缩日志文件(我通过 RollingFileAppender 进行)?
Is it possible to compress log files (I doing it via RollingFileAppender )?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
是否可以压缩日志文件(我通过 RollingFileAppender 进行)?
Is it possible to compress log files (I doing it via RollingFileAppender )?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
log4j extras 对此有支持。
只需将以下内容添加到您的
RollingFileAppender
配置中,并让文件名以 .gz 结尾,即可自动压缩您的日志文件:有关更多详细信息,请检查 Javadoc
log4j extras has support for that.
Just add the following to your
RollingFileAppender
configuration and have the filename end in .gz to automagically compress your log files:For more details check the Javadoc
尝试 Log4j v2.x
我发现了这个很好的答案,但随后继续调查了一下,log4j 2 已经出来了!
现在您可以使用基本库进行压缩以及更多...这真是太棒了!
RollingFileAppender - 我正在寻找兼具两者的东西基于时间和基于大小的滚动,以及压缩......它两者都有!我可以放弃我的 syslog4j 库,因为这个也有它!
除非确实必要,否则请不要使用 log4j 1.2 + extras。
Try Log4j v2.x
I came upon this great answer, but then kept investigating a bit and log4j 2 is out!
Now you can have compression with the basic library and much, much more... it's just awesome!
RollingFileAppender - I was looking for something that had both timeBased and sizeBased rolling, and with compression... it has both! and I can drop my syslog4j library since this one has it also!
Please don't use log4j 1.2 + extras unless you really have to.
我知道这并不能完全回答您的问题,但它确实提出了替代解决方案。
我们处理这个问题的方法是在一天结束时运行一个批处理进程,将之前的所有日志文件压缩到今天的日期,删除一周之前的任何日志文件,然后将它们复制到另一个文件服务器。这样,应用程序不需要消耗任何 CPU 周期来执行此操作,并且在服务器上我们有不超过一周的日志,在另一个文件服务器上我们有较旧的日志文件。
I know this does not exactly answer your question, but it does propose an alternate solution.
The way we handle that is by having a batch process run at the end of the day that compresses any prior log files to today's date, get's rid of any prior to a week old and then copies them off to another file server. This way the application does not need to consume any CPU cycles doing this and on the server we have logs that are no older than a week and on another file server we have older log files.
我看到的唯一另一件事是将 log4j 升级到 1.3.15/1.4 以上,并使用 TimeBasedRollingPolicy 滚轮启用自动压缩,但这本质上需要升级 log4j(以及应用程序的兼容性)
嗯..可能是另一个更好的事情是让 log4j 在文件滚动后执行命令。因此,我可以使用其他一些压缩逻辑(例如 bzip 或 lzop 等)来代替 gzip。如果我今天在 log4j 中拥有此功能,这将是另一种方法。
The only other thing I see is upgrade log4j to more than 1.3.15/1.4 and use TimeBasedRollingPolicy roller to have automatic compression enabled, but that would require an upgrade of log4j essentially (and compatibility of the app as well)
Hmmm..may be another better thing to have is let have log4j execute a command once the file is rolled. So instead of gzip, I can use some other compression logic like bzip, or lzop etc.. that would be another approach if I have this facility in log4j today.