Search in sources :

Example 1 with StatusData

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

the class HttpAppenderTest method testAppendErrorIgnore.

@Test
public void testAppendErrorIgnore() throws Exception {
    wireMockRule.stubFor(post(urlEqualTo("/test/log4j/")).willReturn(FAILURE_RESPONSE));
    StatusLogger.getLogger().registerListener(new StatusListener() {

        @Override
        public void log(StatusData data) {
            error = data;
        }

        @Override
        public Level getStatusLevel() {
            return Level.ERROR;
        }

        @Override
        public void close() throws IOException {
        }
    });
    error = null;
    final Appender appender = HttpAppender.newBuilder().withName("Http").withLayout(JsonLayout.createDefaultLayout()).setConfiguration(ctx.getConfiguration()).setUrl(new URL("http://localhost:" + wireMockRule.port() + "/test/log4j/")).build();
    appender.append(createLogEvent());
    wireMockRule.verify(postRequestedFor(urlEqualTo("/test/log4j/")).withHeader("Host", containing("localhost")).withHeader("Content-Type", containing("application/json")).withRequestBody(containing("\"message\" : \"" + LOG_MESSAGE + "\"")));
    assertNotNull(error);
    assertEquals(Level.ERROR, error.getLevel());
    assertEquals("Unable to send HTTP in appender [Http]", error.getMessage().toString());
}
Also used : Appender(org.apache.logging.log4j.core.Appender) Level(org.apache.logging.log4j.Level) StatusListener(org.apache.logging.log4j.status.StatusListener) IOException(java.io.IOException) StatusData(org.apache.logging.log4j.status.StatusData) URL(java.net.URL) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 URL (java.net.URL)1 Level (org.apache.logging.log4j.Level)1 Appender (org.apache.logging.log4j.core.Appender)1 StatusData (org.apache.logging.log4j.status.StatusData)1 StatusListener (org.apache.logging.log4j.status.StatusListener)1 Test (org.junit.Test)1