Search in sources :

Example 31 with AbstractJacksonLayout

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

the class XmlLayoutTest method testAdditionalFields.

@Test
public void testAdditionalFields() throws Exception {
    final AbstractJacksonLayout layout = XmlLayout.newBuilder().setLocationInfo(false).setProperties(false).setIncludeStacktrace(false).setAdditionalFields(new KeyValuePair[] { new KeyValuePair("KEY1", "VALUE1"), new KeyValuePair("KEY2", "${java:runtime}") }).setCharset(StandardCharsets.UTF_8).setConfiguration(ctx.getConfiguration()).build();
    final String str = layout.toSerializable(LogEventFixtures.createLogEvent());
    assertTrue(str, str.contains("<KEY1>VALUE1</KEY1>"));
    assertTrue(str, str.contains("<KEY2>" + new JavaLookup().getRuntime() + "</KEY2>"));
}
Also used : KeyValuePair(org.apache.logging.log4j.core.util.KeyValuePair) AbstractJacksonLayout(org.apache.logging.log4j.jackson.AbstractJacksonLayout) JavaLookup(org.apache.logging.log4j.core.lookup.JavaLookup) Test(org.junit.Test)

Example 32 with AbstractJacksonLayout

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

the class XmlLayoutTest method testIncludeNullDelimiterFalse.

@Test
public void testIncludeNullDelimiterFalse() throws Exception {
    final AbstractJacksonLayout layout = XmlLayout.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) 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