RSS Feed for This PostCurrent Article

Java: Log4j Performance Pitfalls

Apache Log4j is one of the popular logging frameworks used today even though logging features are introduced starting JDK 5. There is also log5j which supports logger facade that supports printf style message format for both performance and ease of use.

There are a lot of useful information that you can print out to the outputs configured (e.g. file, console, etc). Nonetheless, here are some conversion patterns that you should be careful in using since it impacts the application performance as described in log4j documentation.

Conversion Pattern Descriptions
        C

Used to output the fully qualified class name of the caller issuing the logging request. This conversion specifier can be optionally followed by precision specifier, that is a decimal constant in brackets.

If a precision specifier is given, then only the corresponding number of right most components of the class name will be printed. By default the class name is output in fully qualified form.

For example, for the class name “org.apache.xyz.SomeClass”, the pattern %C{1} will output “SomeClass”.

WARNING Generating the caller class information is slow. Thus, it’s use should be avoided unless execution speed is not an issue.

       F

Used to output the file name where the logging request was issued.

WARNING Generating caller location information is extremely slow. It’s use should be avoided unless execution speed is not an issue.

       L

Used to output the line number from where the logging request was issued.

WARNING Generating caller location information is extremely slow. It’s use should be avoided unless execution speed is not an issue.

       M

Used to output the method name where the logging request was issued.

WARNING Generating caller location information is extremely slow. It’s use should be avoided unless execution speed is not an issue.


Trackback URL


RSS Feed for This Post1 Comment(s)

  1. Swiety | Nov 2, 2009 | Reply

    Don’t forget about ‘l’ option:

    Used to output location information of the caller which generated the logging event.
    The location information depends on the JVM implementation but usually consists of the fully qualified name of the calling method followed by the callers source the file name and line number between parentheses.

    The location information can be very useful. ***However, it’s generation is extremely slow. It’s use should be avoided unless execution speed is not an issue.***

Sorry, comments for this entry are closed at this time.