title: Java Lambda Expression and Logging
body: <p>I was reading the new features of Log4j2 and there's a feature that enables</p>
  
  <p><strong>"Java 8 lambda support for lazy logging"</strong></p>
  
  <p>And it gives two examples</p>
  
  <p>The first one is the bad practice</p>
  
  <pre><code>// pre-Java 8 style optimization: explicitly check the log level
  // to make sure the expensiveOperation() method is only called if necessary
   if (logger.isTraceEnabled()) {
    logger.trace("Some long-running operation returned {}", expensiveOperation());
   }
  </code></pre>
  
  <p>And the second one is the good practice</p>
  
  <pre><code>// Java-8 style optimization: no need to explicitly check the log level:
  // the lambda expression is not evaluated if the TRACE level is not enabled
  logger.trace("Some long-running operation returned {}", () -&gt; expensiveOperation());
  </code></pre>
  
  <p>Where is being made the checking if the requested log level is enabled ?
  <code>"logger.isTraceEnabled()"</code> ?</p>