Hacker News new | ask | show | jobs
by CHY872 3618 days ago
Fyi, 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.
2 comments

You 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.
No good if you're computing the message somehow. e.g.

    logger.debug(generateSomethingLarge());
Generally you would log with placeholders, like

    logger.debug("My logger message has placeholders {}, {}, {}", some, objects, toLog);
which avoids the issue.