Search in sources :

Example 16 with ListAppender

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

the class CallerInformationTest method testMethodLogger.

@Test
public void testMethodLogger() throws Exception {
    final ListAppender app = ctx.getListAppender("Method").clear();
    final Logger logger = Logger.getLogger("MethodLogger");
    logger.info("More messages.");
    logger.warning("CATASTROPHE INCOMING!");
    logger.severe("ZOMBIES!!!");
    logger.warning("brains~~~");
    logger.info("Itchy. Tasty.");
    final List<String> messages = app.getMessages();
    assertEquals("Incorrect number of messages.", 5, messages.size());
    for (final String message : messages) {
        assertEquals("Incorrect caller method name.", "testMethodLogger", message);
    }
}
Also used : ListAppender(org.apache.logging.log4j.core.test.appender.ListAppender) Logger(java.util.logging.Logger) Test(org.junit.Test)

Example 17 with ListAppender

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

the class IoBuilderCallerInfoTesting method assertMessages.

public void assertMessages(final String msg, final int size, final String methodName) {
    final ListAppender appender = ctx.getListAppender("ClassAndMethod");
    assertEquals(msg + ".size", size, appender.getMessages().size());
    for (final String message : appender.getMessages()) {
        assertEquals(msg + " has incorrect caller info", this.getClass().getName() + '.' + methodName, message);
    }
}
Also used : ListAppender(org.apache.logging.log4j.core.test.appender.ListAppender)

Example 18 with ListAppender

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

the class IoBuilderTest method testNoArgBuilderCallerClassInfo.

@Test
public void testNoArgBuilderCallerClassInfo() throws Exception {
    try (final PrintStream ps = IoBuilder.forLogger().buildPrintStream()) {
        ps.println("discarded");
        final ListAppender app = context.getListAppender("IoBuilderTest");
        final List<String> messages = app.getMessages();
        assertThat(messages, not(empty()));
        assertThat(messages, hasSize(1));
        final String message = messages.get(0);
        assertThat(message, startsWith(getClass().getName() + ".testNoArgBuilderCallerClassInfo"));
        app.clear();
    }
}
Also used : PrintStream(java.io.PrintStream) ListAppender(org.apache.logging.log4j.core.test.appender.ListAppender) Test(org.junit.Test)

Example 19 with ListAppender

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

the class BasicArbiterTest 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 : ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) ListAppender(org.apache.logging.log4j.core.test.appender.ListAppender) Appender(org.apache.logging.log4j.core.Appender) ListAppender(org.apache.logging.log4j.core.test.appender.ListAppender) Test(org.junit.jupiter.api.Test)

Example 20 with ListAppender

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

the class SelectArbiterTest 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 : ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) ListAppender(org.apache.logging.log4j.core.test.appender.ListAppender) Appender(org.apache.logging.log4j.core.Appender) ListAppender(org.apache.logging.log4j.core.test.appender.ListAppender) Test(org.junit.jupiter.api.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