Log4j 2 lambda "lazy logging"

Viewed 2580

The Log4j 2 manual gives an example of how to use lambdas for "lazy logging":

logger.trace("Some long-running operation returned {}", () -> expensiveOperation());

It also gives an example of how to use format parameters to avoid unnecessary string concatenation:

logger.debug("Logging in user {} with birthday {}", user.getName(), user.getBirthdayCalendar());

My question: Can I gain the same performance benefits by simply supplying one lambda with a normal string concatenation approach?

logger.trace(() -> "Concatting " + user.getName() + " with " + expensiveOperation());
1 Answers
Related