Search in sources :

Example 6 with JavaLookup

use of org.apache.logging.log4j.core.lookup.JavaLookup 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)

Aggregations

JavaLookup (org.apache.logging.log4j.core.lookup.JavaLookup)6 KeyValuePair (org.apache.logging.log4j.core.util.KeyValuePair)4 Test (org.junit.Test)4 AbstractJacksonLayout (org.apache.logging.log4j.jackson.AbstractJacksonLayout)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Logger (org.apache.logging.log4j.Logger)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 InflaterInputStream (java.util.zip.InflaterInputStream)1 EncodingListAppender (org.apache.logging.log4j.core.test.appender.EncodingListAppender)1 ListAppender (org.apache.logging.log4j.core.test.appender.ListAppender)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.jupiter.api.Test)1