Our traditional way to do logging is :
if (logger.isDebugEnabled()) {
logger.debug("something to log, and barbarbar {}", object);
}
But what about using lambda expression to do logging to reduce lines of codes and complexity?
logger.debug(() -> return "something to log, and barbarbar " + object);
Is there any reason that slf4j or other logger do not provide this way to do logging? Object creation overhead caused?
Our traditional way to do logging is ...
It is not obligatory to use condition logger.isXXXXEnabled()
in every use case. It's intended to be used only when you log an object that takes significant time to be created. For example when you need to put into log result of some DB query or complex structure converted to XML/JSON, etc.
For other cases this check is excessive.