Class Log4J2Logger

All Implemented Interfaces:
org.junit.rules.TestRule

public class Log4J2Logger extends AnnotatedMethodTemplate<Log4J2Logger.Record>
Record the logging output for a given log4j2 logger.

Usage:

 public class MyTest
   {
      @literal @Rule public Log4JLogger logger = new Log4JLogger(MyTest.class);

      @literal @Test
      @literal @Log4JLogger.Record(loggerClass = MyUnitUnderTest.class, logLevel = Log4JLogger.LogLevel.DEBUG)
       public void myTestMethod() throws Exception
       {
           // call unit under test
           Assert.assertEquals("expected log message", logger.snapshot());
       }
  }
  
 
Since:
7.20
  • Field Details

    • layout

      protected final org.apache.logging.log4j.core.StringLayout layout
  • Constructor Details

    • Log4J2Logger

      public Log4J2Logger(Class testClass)
    • Log4J2Logger

      public Log4J2Logger(Class testClass, org.apache.logging.log4j.core.StringLayout layout)
  • Method Details