Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exactly how slow are C, F, L, l and M of PatternLayout (log4j)?

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?

like image 498
cherouvim Avatar asked Jan 27 '11 17:01

cherouvim


People also ask

What is PatternLayout in Log4j?

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.

What is 5p in Log4j?

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.

How do I print line numbers in Log4j?

if it is line number you can use %L (Used to output the line number from where the logging request was issued.)

Which of the following are format characters used in Log4j?

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.


1 Answers

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.

enter image description here

like image 169
cherouvim Avatar answered Oct 04 '22 15:10

cherouvim