When to use isDebugEnable?

‘One of the best practices for logging with libraries like log4j is to check whether debug is enabled before writing a debug message. This is done by calling the method isDebugEnabled(). But when should you use this method? To answer this question let exeamine two examples:
Example with string concatenation

LOG.debug("The customer  : " + customer.getId + " ordered the article " + article.getId + " on " + new Date());

In the above example there is a new string object created by concatenating all the parameters before the call to debug method is done. This happens regardless of debug is enabled or not which will be an unnecessary performance overhead if debug is disabled.
Example without string concatenation:

if( LOG.isDebugEnabled()) {
  LOG.debug("Before saving the order");
}

In the above code section the if condition is not necessary as there is no String concatenations involved and ends up adding two redundant lines of code. Therefore the best practice is to use an isDebugEnabled only if there is any String concatenation involved in the call to debug. This should also be similar to the use of the other methods like isInfoEnabled, isTraceEnabled

Marva.Net