This sort of code is used to avoid unnecessary memory being allocated on heap. Consider the following
String that is used in the debug message:
log.debug( toString() + " : " + someMessage.toString() );
As you might be knowing, when the '+' operator is used on String objects as in:
toString() + " : " + someMessage.toString()
the resultant String that gets created will be allocated memory on the heap(dynamically at run-time).
Now consider that you *dont* have the check:
if ( log.isDebugEnabled() )
For the statement:
log.debug( toString() + " : " + someMessage.toString() );
to be executed, memory will be allocated on the heap for the resultant string which is passed as a parameter to the debug method. Then later on internally in the debug method there will be a check of whether debug level is enabled for that particular package. If its not enabled, then the memory allocated on the heap will be wasted. To avoid this, the check is made(by using the isDebugEnabled() method) even *before* the String object is created out of the '+' operator on the heap.
This is just a way of saving heap memory
[ July 31, 2006: Message edited by: jaikiran pai ]