This is considered good practice. For example, if there is some string concatenation, it is not evaluated and not checked in log4j, but checked first.
Example:
if ( log.isDebugEnabled() ) { log.debug( "N=" + N + ", a=" + Arrays.toString( a ) ); }
Arrays.toString() method, and concatenation is not performed if debug is not enabled. If there is no if , it is called first and checked later, that is all; -)
My opinion is that when there is a simple line in your example, if there is no need for logging, if there is something more complex (even more complicated, as in my example), this can save some CPU time in working mode (without debugging mode )
You should also understand that when in case of concatenation there is a call to String.valuOf() , which (for non-null objects) calls the toString() method, which can be a performance issue for large data objects (beans with many properties) if you consider that it does not use business logic (therefore, it is "useless").
Betlista
source share