RandomAccessFileAppender

RandomAccessFileAppender

本文介绍了log4j2配置中RollingFile和RollingRandomAccessFile有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们当前的实现中,其中一台服务器为RollingRandomAccessFile设置了log4j2的配置,而另一台则为RollingFile设置了.我想知道两者之间的区别,如果可能的话,两者各自有何利弊.

In our current implementation one of the servers has the configuration for log4j2 set for RollingRandomAccessFile and in the other RollingFile. I would like to know what is the difference between the two and pros and cons of each if possible.

谢谢

推荐答案

主要区别在于性能: http://logging.apache.org/log4j/2 .x/manual/async.html#FileAppender_vs._RandomAccessFileAppender

The main difference is performance:http://logging.apache.org/log4j/2.x/manual/async.html#FileAppender_vs._RandomAccessFileAppender

RandomAccessFileAppender始终被缓冲,而FileAppender提供配置开关(bufferedIO).如果您想确保邮件在磁盘上(例如审核日志记录),则两者都有一个"immediateFlush"配置选项.最后,RandomAccessFileAppender的默认缓冲区大小更大:256 * 1024字节,而FileAppender的默认缓冲区大小为8 * 1024字节(两个追加器的缓冲区大小都可以在配置中设置).

RandomAccessFileAppender is always buffered, while FileAppender provides a config switch (bufferedIO). Both have an "immediateFlush" config option in case you want to be sure your messages are on disk (e.g. audit logging). Finally, the default buffer size for RandomAccessFileAppender is larger: 256*1024 bytes vs 8*1024 bytes for FileAppender (both appenders buffer size can be set in configuration).

另一件事,底层实现在一种情况下使用RandomAccessFile,在另一种情况下使用OutputStream(顾名思义).将RandomAccessFileAppender与unix logrotate实用程序结合使用存在一个已知问题( https://issues.apache .org/jira/browse/LOG4J2-354 ),Log4j小组建议您使用RollingRandomAccessFile进行翻转,并避免使用unix logrotate实用程序.显然FileAppender可以与logrotate结合使用-我们还没有听说过任何问题. (由于该问题已经提到了这两个追加程序的Rolling ...变体,您已经在做正确的事情,我只是想我应该提到它.)

One more thing, the underlying implementation uses a RandomAccessFile in one case and an OutputStream in the other case (as the name suggests). There is a known issue with combining RandomAccessFileAppender with the unix logrotate utility (https://issues.apache.org/jira/browse/LOG4J2-354), and the Log4j team recommends you use the RollingRandomAccessFile for rollover and avoid use of the unix logrotate utility. Apparently FileAppender can be combined with logrotate - we haven't heard of any issues. (Since the question already mentions the Rolling... variant for both appenders you are already doing the right thing, I just thought I should mention it.)

这篇关于log4j2配置中RollingFile和RollingRandomAccessFile有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-06 04:20