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.
Thanks
The main difference is performance: http://logging.apache.org/log4j/2.x/manual/async.html#FileAppender_vs._RandomAccessFileAppender
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).
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With