Interface LogCaptor

  • All Superinterfaces:
    AutoCloseable, SdkAutoCloseable
    All Known Implementing Classes:
    LogCaptor.DefaultLogCaptor, LogCaptor.LogCaptorTestBase

    public interface LogCaptor
    extends SdkAutoCloseable
    A test utility that allows inspection of log statements during testing.

    Can either be used stand-alone for example

    
         try (LogCaptor logCaptor = new LogCaptor.DefaultLogCaptor(Level.INFO)) {
             // Do stuff that you expect to log things
             assertThat(logCaptor.loggedEvents(), is(not(empty())));
         }
     

    Or can extend it to make use of @Before / @After test annotations

    
         class MyTestClass extends LogCaptor.LogCaptorTestBase {
             @Test
             public void someTestThatWeExpectToLog() {
                 // Do stuff that you expect to log things
                 assertThat(loggedEvents(), is(not(empty())));
             }
         }
     
    • Method Detail

      • create

        static LogCaptor create​(org.apache.logging.log4j.Level level)
      • loggedEvents

        List<org.apache.logging.log4j.core.LogEvent> loggedEvents()
      • clear

        void clear()