Rule Definition
While disabling debug logging level in production, it still impacts performance of your application because the method invocation involves the hidden cost of parameter construction.
For example: << cat.debug("Entry number: " + i + " is " + String.valueOf(entry[i])) >> incurs the cost of constructing the message parameter that is converting both integer i and entry[i] to a String and concatenating intermediate strings, regardless of whether the message will be logged or not.
Remediation
Add a if condition with a call to isDebugEnabled() before calling any .debug().
Violation Code Sample
import org.apache.log4j.*;
public class MyClass {
Category cat = Category.getInstance(MyClass.class.getName());
String entry [];
public static void aMethod(int i) {
cat.debug("Entry number: " + i + " is " + String.valueOf(entry[i])); // VIOLATION
}
Fixed Code Sample
import org.apache.log4j.*;
public class MyClass {
Category cat = Category.getInstance(MyClass.class.getName());
String entry [];
public static void aMethod(int i) {
if (cat.isDebugEnabled()) { //FIXED
cat.debug("Entry number: " + i + " is " + String.valueOf(entry[i]));
}
}
Reference
http://www.javaworld.com/jw-11-2000/jw-1122-log4j.html
http://burtbeckwith.com/blog/?cat=8
Related Technologies
JEE
Technical Criterion
Efficiency - Memory, Network and Disk Space Management
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.