Search in sources :

Example 26 with Logger

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

the class CsvJsonParameterLayoutFileAppenderTest method testNoNulCharacters.

public void testNoNulCharacters(final String message, final String expected) throws IOException {
    @SuppressWarnings("resource") final LoggerContext loggerContext = loggerContextRule.getLoggerContext();
    final Logger logger = loggerContext.getLogger("com.example");
    logger.error("log:", message);
    loggerContext.stop();
    final File file = new File(FILE_PATH);
    final byte[] contents = Files.toByteArray(file);
    int count0s = 0;
    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < contents.length; i++) {
        final byte b = contents[i];
        if (b == 0) {
            sb.append(i);
            sb.append(", ");
            count0s++;
        }
    }
    Assert.assertEquals("File contains " + count0s + " 0x00 byte at indices " + sb, 0, count0s);
    final List<String> readLines = Files.readLines(file, Charset.defaultCharset());
    final String actual = readLines.get(0);
    // Assert.assertTrue(actual, actual.contains(message));
    Assert.assertEquals(actual, expected, actual);
    Assert.assertEquals(1, readLines.size());
}
Also used : Logger(org.apache.logging.log4j.core.Logger) LoggerContext(org.apache.logging.log4j.core.LoggerContext) File(java.io.File)

Example 27 with Logger

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

the class ScriptAppenderSelectorTest method logAndCheck.

private void logAndCheck() {
    final Marker marker = MarkerManager.getMarker("HEXDUMP");
    final Logger logger = loggerContextRule.getLogger(ScriptAppenderSelectorTest.class);
    logger.error("Hello");
    final ListAppender listAppender = getListAppender();
    final List<LogEvent> list = listAppender.getEvents();
    assertNotNull("No events generated", list);
    assertTrue("Incorrect number of events. Expected 1, got " + list.size(), list.size() == 1);
    logger.error("World");
    assertTrue("Incorrect number of events. Expected 2, got " + list.size(), list.size() == 2);
    logger.error(marker, "DEADBEEF");
    assertTrue("Incorrect number of events. Expected 3, got " + list.size(), list.size() == 3);
}
Also used : LogEvent(org.apache.logging.log4j.core.LogEvent) ListAppender(org.apache.logging.log4j.test.appender.ListAppender) Marker(org.apache.logging.log4j.Marker) Logger(org.apache.logging.log4j.core.Logger)

Example 28 with Logger

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

the class CsvParameterLayoutTest method testLayoutDefaultObjectArrayMessage.

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

Example 29 with Logger

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

the class CsvParameterLayoutTest method testLayoutDefaultNormal.

@Test
public void testLayoutDefaultNormal() throws Exception {
    final Logger root = this.init.getRootLogger();
    testLayoutNormalApi(root, CsvParameterLayout.createDefaultLayout(), false);
}
Also used : Logger(org.apache.logging.log4j.core.Logger) Test(org.junit.Test)

Example 30 with Logger

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

the class CsvParameterLayoutTest method testLayoutTab.

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

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