It's common knowledge that C
, F
, L
, l
and M
of PatternLayout are slow:
WARNING Generating caller location information is extremely slow and should be avoided unless execution speed is not an issue.
Also, this book mentions that some applications can gain 10% speed only from changing the logging format.
But the question is, exactly how slow are these conversion characters?
Layout class and overrides the format() method to structure the logging information according to a supplied pattern. PatternLayout is also a simple Layout object that provides the following-Bean Property which can be set using the configuration file: Sr.No. Property & Description.
1.2 Log4j Conversion Pattern -5p is the format modifier for the conversion character p (i.e. priority). This justifies the priority name with a minimum of 5 characters.
if it is line number you can use %L (Used to output the line number from where the logging request was issued.)
The format characters used in log4j are, L- it is used to output the line number from where the logging request was processed or issued. m- It is used to output the application supplied message related to the logging event. p- It is used to output the priority of the logging event.
I measured locally on my computer using a FileAppender. I warmed up the test nicely, measured many executions and averaged the (relatively consistent) results. The loop contained execs++;log.info("t");
The exact numbers do not matter (because they depend on my computer) but proportions do. I used log4j-1.2.16.jar on Java 1.6.0_10 (Client VM).
It turns out that whenever any of the C, F, L, l or M
appeared in the pattern, logging was at least 5 times slower.
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