Search in sources :

Example 46 with ListAppender

use of org.apache.logging.log4j.core.test.appender.ListAppender in project logging-log4j2 by apache.

the class RoutesScriptAppenderTest method logAndCheck.

private void logAndCheck() {
    final Marker marker = MarkerManager.getMarker("HEXDUMP");
    final Logger logger = loggerContextRule.getLogger(RoutesScriptAppenderTest.class);
    logger.error("Hello");
    final ListAppender listAppender = getListAppender();
    assertEquals("Incorrect number of events", 1, listAppender.getEvents().size());
    logger.error("World");
    assertEquals("Incorrect number of events", 2, listAppender.getEvents().size());
    logger.error(marker, "DEADBEEF");
    assertEquals("Incorrect number of events", 3, listAppender.getEvents().size());
}
Also used : ListAppender(org.apache.logging.log4j.core.test.appender.ListAppender) Marker(org.apache.logging.log4j.Marker) Logger(org.apache.logging.log4j.core.Logger)

Example 47 with ListAppender

use of org.apache.logging.log4j.core.test.appender.ListAppender in project logging-log4j2 by apache.

the class ScriptArbiterTest method prodTest.

@Test
public void prodTest() {
    System.setProperty("env", "prod");
    loggerContext = Configurator.initialize(null, CONFIG);
    assertNotNull(loggerContext);
    Appender app = loggerContext.getConfiguration().getAppender("Out");
    assertNotNull(app);
    assertTrue(app instanceof ListAppender);
}
Also used : Appender(org.apache.logging.log4j.core.Appender) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) ListAppender(org.apache.logging.log4j.core.test.appender.ListAppender) ListAppender(org.apache.logging.log4j.core.test.appender.ListAppender) Test(org.junit.jupiter.api.Test)

Example 48 with ListAppender

use of org.apache.logging.log4j.core.test.appender.ListAppender in project logging-log4j2 by apache.

the class ScriptAppenderSelectorTest method verify.

static void verify(final Configuration config) {
    assertNull(config.getAppender("List1"), "List1 appender should not be initialized");
    assertNull(config.getAppender("List2"), "List2 appender should not be initialized");
    final ListAppender listAppender = config.getAppender("SelectIt");
    assertNotNull(listAppender);
    final ExtendedLogger logger = config.getLoggerContext().getLogger(ScriptAppenderSelectorTest.class);
    logger.error("Hello");
    assertThat(listAppender.getEvents(), hasSize(1));
    logger.error("World");
    assertThat(listAppender.getEvents(), hasSize(2));
    logger.error(MarkerManager.getMarker("HEXDUMP"), "DEADBEEF");
    assertThat(listAppender.getEvents(), hasSize(3));
}
Also used : ExtendedLogger(org.apache.logging.log4j.spi.ExtendedLogger) ListAppender(org.apache.logging.log4j.core.test.appender.ListAppender)

Example 49 with ListAppender

use of org.apache.logging.log4j.core.test.appender.ListAppender in project logging-log4j2 by apache.

the class DefaultRouteScriptAppenderTest method logAndCheck.

private void logAndCheck() {
    final Marker marker = MarkerManager.getMarker("HEXDUMP");
    final Logger logger = loggerContextRule.getLogger(DefaultRouteScriptAppenderTest.class);
    logger.error("Hello");
    final ListAppender listAppender = getListAppender();
    assertEquals("Incorrect number of events", 1, listAppender.getEvents().size());
    logger.error("World");
    assertEquals("Incorrect number of events", 2, listAppender.getEvents().size());
    logger.error(marker, "DEADBEEF");
    assertEquals("Incorrect number of events", 3, listAppender.getEvents().size());
}
Also used : ListAppender(org.apache.logging.log4j.core.test.appender.ListAppender) Marker(org.apache.logging.log4j.Marker) Logger(org.apache.logging.log4j.core.Logger)

Example 50 with ListAppender

use of org.apache.logging.log4j.core.test.appender.ListAppender in project logging-log4j2 by apache.

the class CallerInformationTest method testClassLogger.

@Test
public void testClassLogger() throws Exception {
    final ListAppender app = ctx.getListAppender("Class").clear();
    final Logger logger = LoggerFactory.getLogger("ClassLogger");
    logger.info("Ignored message contents.");
    logger.warn("Verifying the caller class is still correct.");
    logger.error("Hopefully nobody breaks me!");
    final List<String> messages = app.getMessages();
    assertEquals("Incorrect number of messages.", 3, messages.size());
    for (final String message : messages) {
        assertEquals("Incorrect caller class name.", this.getClass().getName(), message);
    }
}
Also used : ListAppender(org.apache.logging.log4j.core.test.appender.ListAppender) Logger(org.slf4j.Logger) Test(org.junit.Test)

Aggregations

ListAppender (org.apache.logging.log4j.core.test.appender.ListAppender)60 Test (org.junit.Test)24 Appender (org.apache.logging.log4j.core.Appender)21 Test (org.junit.jupiter.api.Test)15 Configuration (org.apache.logging.log4j.core.config.Configuration)6 StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)5 AbstractLogger (org.apache.logging.log4j.spi.AbstractLogger)5 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)4 KeyValuePair (org.apache.logging.log4j.core.util.KeyValuePair)4 AbstractJacksonLayout (org.apache.logging.log4j.jackson.AbstractJacksonLayout)4 Marker (org.apache.logging.log4j.Marker)3 LogEvent (org.apache.logging.log4j.core.LogEvent)3 Logger (org.apache.logging.log4j.core.Logger)3 DefaultConfiguration (org.apache.logging.log4j.core.config.DefaultConfiguration)3 ExtendedLogger (org.apache.logging.log4j.spi.ExtendedLogger)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 Logger (java.util.logging.Logger)2 Log (org.apache.commons.logging.Log)2 LoggerContext (org.apache.logging.log4j.core.LoggerContext)2 RoutingAppender (org.apache.logging.log4j.core.appender.routing.RoutingAppender)2