I always see it is better to check whether log.isDebugEnabled before adding a log.debug statement.
I guess it should be taken care by the logging framework, could you please let me know what is the advantage of having this condition check?
Consider the following example:
if (log.isDebugEnabled()) {
log.debug("This is my complicated object" + veryComplicatedObject.toString());
}
String concatenation may be expensive (memory-wise), and there is no reason to perform it if we aren't going to log it anyway. Checking the logging level beforehand saves constructing redundant strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With