title: Log4j 2 lambda "lazy logging"
body: <p>The <a href="https://logging.apache.org/log4j/2.0/manual/api.html" rel="nofollow noreferrer">Log4j 2 manual</a> gives an example of how to use lambdas for "lazy logging":</p>
  
  <pre><code>logger.trace("Some long-running operation returned {}", () -&gt; expensiveOperation());
  </code></pre>
  
  <p>It also gives an example of how to use format parameters to avoid unnecessary string concatenation:</p>
  
  <pre><code>logger.debug("Logging in user {} with birthday {}", user.getName(), user.getBirthdayCalendar());
  </code></pre>
  
  <p>My question: Can I gain the same performance benefits by simply supplying one lambda with a normal string concatenation approach?</p>
  
  <pre><code>logger.trace(() -&gt; "Concatting " + user.getName() + " with " + expensiveOperation());
  </code></pre>