This is considered as good practice. For example if there is some string concatenation it's not evaluated and checked in log4j, but it is checked first.
Example:
if ( log.isDebugEnabled() ) {
log.debug( "N=" + N + ", a=" + Arrays.toString( a ) );
}
method Arrays.toString()
and also concatenation is not performed if debug is not enabled. If there is no if
it is invoked first and checked later, that's all ;-)
My opinion is that when there is simple String as in your example the if around the logging is not needed, if there is something more complicated (even more complicated as in my example) this can save some CPU time in production mode (without debug mode enabled).
You have to realize also that when in case of concatenation there is String.valuOf()
call which (for not null objects) calls toString()
method, which can be really performance issue for big data objects (beans with many properties) if you consider that it's invoking no business logic (therefore it is "useless").