diff --git a/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/LambdaExpressionsIntegrationTest.java b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/LambdaExpressionsIntegrationTest.java new file mode 100644 index 0000000000..a1454c16cc --- /dev/null +++ b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/LambdaExpressionsIntegrationTest.java @@ -0,0 +1,33 @@ +package com.baeldung.logging.log4j2.tests; + +import java.util.Random; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.junit.Test; + +public class LambdaExpressionsIntegrationTest { + + private static final Logger logger = LogManager.getRootLogger(); + + @Test + public void whenCheckLogMessage_thenOk() { + if (logger.isTraceEnabled()) { + logger.trace("Numer is {}", getRandomNumber()); + } + } + + @Test + public void whenUseLambdaExpression_thenOk() { + logger.trace("Number is {}", () -> getRandomNumber()); + logger.trace("Name is {} and age is {}", () -> getName(), () -> getRandomNumber()); + } + + private int getRandomNumber() { + return (new Random()).nextInt(10); + } + + private String getName() { + return "John"; + } +}