Search in sources :

Example 21 with AbstractJacksonLayout

use of org.apache.logging.log4j.jackson.AbstractJacksonLayout in project logging-log4j2 by apache.

the class JsonLayoutTest method testIncludeNullDelimiterTrue.

@Test
public void testIncludeNullDelimiterTrue() throws Exception {
    final AbstractJacksonLayout layout = JsonLayout.newBuilder().setCompact(true).setIncludeNullDelimiter(true).build();
    final String str = layout.toSerializable(LogEventFixtures.createLogEvent());
    assertTrue(str.endsWith("\0"));
}
Also used : AbstractJacksonLayout(org.apache.logging.log4j.jackson.AbstractJacksonLayout) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 22 with AbstractJacksonLayout

use of org.apache.logging.log4j.jackson.AbstractJacksonLayout in project logging-log4j2 by apache.

the class JsonLayoutTest method testDefaultCharset.

@Test
public void testDefaultCharset() {
    final AbstractJacksonLayout layout = JsonLayout.createDefaultLayout();
    assertEquals(StandardCharsets.UTF_8, layout.getCharset());
}
Also used : AbstractJacksonLayout(org.apache.logging.log4j.jackson.AbstractJacksonLayout) Test(org.junit.Test)

Example 23 with AbstractJacksonLayout

use of org.apache.logging.log4j.jackson.AbstractJacksonLayout in project logging-log4j2 by apache.

the class JsonLayoutTest method testLayoutLoggerName.

@Test
public void testLayoutLoggerName() throws Exception {
    final boolean propertiesAsList = false;
    // @formatter:off
    final AbstractJacksonLayout layout = JsonLayout.newBuilder().setLocationInfo(false).setProperties(false).setPropertiesAsList(propertiesAsList).setComplete(false).setCompact(true).setEventEol(false).setCharset(StandardCharsets.UTF_8).setIncludeStacktrace(true).build();
    // @formatter:on
    // @formatter:off
    final Log4jLogEvent expected = Log4jLogEvent.newBuilder().setLoggerName("a.B").setLoggerFqcn("f.q.c.n").setLevel(Level.DEBUG).setMessage(new SimpleMessage("M")).setThreadName("threadName").setTimeMillis(1).build();
    // @formatter:on
    final String str = layout.toSerializable(expected);
    assertTrue(str, str.contains("\"loggerName\":\"a.B\""));
    final Log4jLogEvent actual = new Log4jJsonObjectMapper(propertiesAsList, true, false, false).readValue(str, Log4jLogEvent.class);
    assertEquals(expected.getLoggerName(), actual.getLoggerName());
    assertEquals(expected, actual);
}
Also used : Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) AbstractJacksonLayout(org.apache.logging.log4j.jackson.AbstractJacksonLayout) Log4jJsonObjectMapper(org.apache.logging.log4j.jackson.json.Log4jJsonObjectMapper) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 24 with AbstractJacksonLayout

use of org.apache.logging.log4j.jackson.AbstractJacksonLayout in project logging-log4j2 by apache.

the class JsonLayoutTest method testContentType.

@Test
public void testContentType() {
    final AbstractJacksonLayout layout = JsonLayout.createDefaultLayout();
    assertEquals("application/json; charset=UTF-8", layout.getContentType());
}
Also used : AbstractJacksonLayout(org.apache.logging.log4j.jackson.AbstractJacksonLayout) Test(org.junit.Test)

Example 25 with AbstractJacksonLayout

use of org.apache.logging.log4j.jackson.AbstractJacksonLayout in project logging-log4j2 by apache.

the class JsonLayoutTest method testIncludeNullDelimiterFalse.

@Test
public void testIncludeNullDelimiterFalse() throws Exception {
    final AbstractJacksonLayout layout = JsonLayout.newBuilder().setCompact(true).setIncludeNullDelimiter(false).build();
    final String str = layout.toSerializable(LogEventFixtures.createLogEvent());
    assertFalse(str.endsWith("\0"));
}
Also used : AbstractJacksonLayout(org.apache.logging.log4j.jackson.AbstractJacksonLayout) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

AbstractJacksonLayout (org.apache.logging.log4j.jackson.AbstractJacksonLayout)32 Test (org.junit.Test)26 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)14 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 KeyValuePair (org.apache.logging.log4j.core.util.KeyValuePair)7 Log4jJsonObjectMapper (org.apache.logging.log4j.jackson.json.Log4jJsonObjectMapper)5 Appender (org.apache.logging.log4j.core.Appender)4 Configuration (org.apache.logging.log4j.core.config.Configuration)4 MutableLogEvent (org.apache.logging.log4j.core.impl.MutableLogEvent)4 ListAppender (org.apache.logging.log4j.core.test.appender.ListAppender)4 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)4 AbstractLogger (org.apache.logging.log4j.spi.AbstractLogger)4 JavaLookup (org.apache.logging.log4j.core.lookup.JavaLookup)3 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)3 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)3 DefaultConfiguration (org.apache.logging.log4j.core.config.DefaultConfiguration)2 Log4jYamlObjectMapper (org.apache.logging.log4j.jackson.yaml.Log4jYamlObjectMapper)2 Message (org.apache.logging.log4j.message.Message)2 RingBufferLogEvent (org.apache.logging.log4j.core.async.RingBufferLogEvent)1 DummyNanoClock (org.apache.logging.log4j.core.time.internal.DummyNanoClock)1