Search in sources :

Example 6 with StatusLogger

use of org.apache.logging.log4j.status.StatusLogger in project logging-log4j2 by apache.

the class AbstractActionTest method testErrorsAreLoggedToStatusLogger.

@Test
public void testErrorsAreLoggedToStatusLogger() {
    StatusLogger statusLogger = StatusLogger.getLogger();
    statusLogger.clear();
    new AbstractAction() {

        @Override
        public boolean execute() {
            throw new AssertionError();
        }
    }.run();
    List<StatusData> statusDataList = statusLogger.getStatusData();
    assertThat(statusDataList, hasSize(1));
    StatusData statusData = statusDataList.get(0);
    assertEquals(Level.WARN, statusData.getLevel());
    String formattedMessage = statusData.getFormattedStatus();
    assertThat(formattedMessage, containsString("Exception reported by action"));
}
Also used : StatusLogger(org.apache.logging.log4j.status.StatusLogger) Matchers.containsString(org.hamcrest.Matchers.containsString) StatusData(org.apache.logging.log4j.status.StatusData) Test(org.junit.jupiter.api.Test)

Aggregations

StatusLogger (org.apache.logging.log4j.status.StatusLogger)6 StatusData (org.apache.logging.log4j.status.StatusData)4 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Test (org.junit.jupiter.api.Test)3 StatusListener (org.apache.logging.log4j.status.StatusListener)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1