3 ms·
Well, to be really fair compare it with : if(logger.isDebugEnabled()){ logger.debug("..."); } And yeah, it requires a bit more typting if you want
by zer0gravity 10y ago
Well, to be really fair compare it with :
if(logger.isDebugEnabled()){
logger.debug("...");
}
And yeah, it requires a bit more typting if you want to enforce a certain event format and want to add more parameters. But you only do that once, and I'd say you gain much more for your effort.
- CHY872 10y agoFyi, intended usage with most Java loggers is to just call logger.debug("..."); and ignore the conditional. If `!logger.isDebugEnabled` then the logger will ignore the message, so it avoids boilerplate.
- zer0gravity 10y agoYou want to wrap it in an if in order to avoid doing extra work ( like string concatenation or whatever ) and save some computation. It's to improve performance when logging is not enabled.
- CHY872 10y agoGenerally you would log with placeholders, like logger.debug("My logger message has placeholders {}, {}, {}", some, objects, toLog); which avoids the issue.
- jestar_jokin 10y agoNo good if you're computing the message somehow. e.g. logger.debug(generateSomethingLarge());
- CHY872 10y agoGenerally you would log with placeholders, like logger.debug("My logger message has placeholders {}, {}, {}", some, objects, toLog); which avoids the issue.