Search in sources :

Example 31 with Logger

use of org.apache.logging.log4j.core.Logger in project logging-log4j2 by apache.

the class CsvParameterLayoutTest method testLogJsonArgument.

@Test
public void testLogJsonArgument() throws InterruptedException {
    final ListAppender appender = (ListAppender) init.getAppender("List");
    appender.countDownLatch = new CountDownLatch(4);
    appender.clear();
    final Logger logger = (Logger) LogManager.getRootLogger();
    final String json = "{\"id\":10,\"name\":\"Alice\"}";
    logger.error("log:{}", json);
    // wait until background thread finished processing
    final int msgCount = 1;
    if (appender.getMessages().size() < msgCount) {
        appender.countDownLatch.await(5, TimeUnit.SECONDS);
    }
    assertEquals("Background thread did not finish processing: msg count", msgCount, appender.getMessages().size());
    // don't stop appender until background thread is done
    appender.stop();
    final List<String> list = appender.getMessages();
    final String eventStr = list.get(0).toString();
    Assert.assertTrue(eventStr, eventStr.contains(json));
}
Also used : ListAppender(org.apache.logging.log4j.test.appender.ListAppender) CountDownLatch(java.util.concurrent.CountDownLatch) Logger(org.apache.logging.log4j.core.Logger) Test(org.junit.Test)

Example 32 with Logger

use of org.apache.logging.log4j.core.Logger in project logging-log4j2 by apache.

the class CsvParameterLayoutAllAsyncTest method testLayoutTab.

@Test
public void testLayoutTab() throws Exception {
    final Logger root = (Logger) LogManager.getRootLogger();
    CsvParameterLayoutTest.testLayoutNormalApi(root, CsvParameterLayout.createLayout(CSVFormat.TDF), true);
}
Also used : Logger(org.apache.logging.log4j.core.Logger) Test(org.junit.Test)

Example 33 with Logger

use of org.apache.logging.log4j.core.Logger in project logging-log4j2 by apache.

the class CsvParameterLayoutAllAsyncTest method testLayoutDefaultObjectArrayMessage.

@Test
public void testLayoutDefaultObjectArrayMessage() throws Exception {
    final Logger root = (Logger) LogManager.getRootLogger();
    CsvParameterLayoutTest.testLayoutNormalApi(root, CsvParameterLayout.createDefaultLayout(), true);
}
Also used : Logger(org.apache.logging.log4j.core.Logger) Test(org.junit.Test)

Example 34 with Logger

use of org.apache.logging.log4j.core.Logger in project logging-log4j2 by apache.

the class AbstractFilterTest method verifyMethodsWithUnrolledVarargs.

private void verifyMethodsWithUnrolledVarargs(final ConcreteFilter filter, final Filter.Result expected) {
    final Logger logger = null;
    final Level level = null;
    final Marker marker = null;
    assertEquals(expected, filter.filter(logger, level, marker, "", 1));
    assertEquals(expected, filter.filter(logger, level, marker, "", 1, 2));
    assertEquals(expected, filter.filter(logger, level, marker, "", 1, 2, 3));
    assertEquals(expected, filter.filter(logger, level, marker, "", 1, 2, 3, 4));
    assertEquals(expected, filter.filter(logger, level, marker, "", 1, 2, 3, 4, 5));
    assertEquals(expected, filter.filter(logger, level, marker, "", 1, 2, 3, 4, 5, 6));
    assertEquals(expected, filter.filter(logger, level, marker, "", 1, 2, 3, 4, 5, 6, 7));
    assertEquals(expected, filter.filter(logger, level, marker, "", 1, 2, 3, 4, 5, 6, 7, 8));
    assertEquals(expected, filter.filter(logger, level, marker, "", 1, 2, 3, 4, 5, 6, 7, 8, 9));
    assertEquals(expected, filter.filter(logger, level, marker, "", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
}
Also used : Level(org.apache.logging.log4j.Level) Marker(org.apache.logging.log4j.Marker) Logger(org.apache.logging.log4j.core.Logger)

Aggregations

Logger (org.apache.logging.log4j.core.Logger)34 Test (org.junit.Test)20 LoggerContext (org.apache.logging.log4j.core.LoggerContext)6 Appender (org.apache.logging.log4j.core.Appender)5 StatusLogger (org.apache.logging.log4j.status.StatusLogger)5 Field (java.lang.reflect.Field)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 Marker (org.apache.logging.log4j.Marker)4 ListAppender (org.apache.logging.log4j.test.appender.ListAppender)4 IgniteLogger (org.apache.ignite.IgniteLogger)3 LogEvent (org.apache.logging.log4j.core.LogEvent)3 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)3 List (java.util.List)2 Map (java.util.Map)2 ExecutorService (java.util.concurrent.ExecutorService)2 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)2 RollingFileAppender (org.apache.logging.log4j.core.appender.RollingFileAppender)2 RoutingAppender (org.apache.logging.log4j.core.appender.routing.RoutingAppender)2 Log4jLogger (org.apache.logging.slf4j.Log4jLogger)2 LogLevel (com.torodb.packaging.config.model.generic.LogLevel)1