Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j DailyRollingFileAppender vs ConsoleAppender performance

We're using Log4j v1.2.14. We're already using org.apache.log4j.ConsoleAppender and now we've a requirement/need to have daily rotating logs in place. Hence, we're planning to use org.apache.log4j.DailyRollingFileAppender to have daily rotating logs.

My question is, is DailyRollingFileAppender an additional overhead/have performance impact over ConsoleAppender, because it has to additionally check for whether the file has to be rotated/rollover in each print statement?

Any opinions/user experience are also appreciated.

like image 539
Gnanam Avatar asked Jun 15 '26 14:06

Gnanam


1 Answers

Your arguments are correct and logic dictates that an overhead/performance impact exists. How much? You should measure it by yourself if you're afraid of the performance hit.

It really depends on how many logging statements you have. Lots of debugging statements are the worst because they can impact performance, unless you are using guards of type logger.isDebugEnabled().

If you can afford it, I'd suggest switching to slf4j with Logback as underlying implementation. Logback's main focus is speed and it seems to go to great lengths to make sure it's faster than other logging systems.

like image 145
darioo Avatar answered Jun 18 '26 04:06

darioo