Search in sources :

Example 11 with MutableLogEvent

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

the class YamlLayoutTest method testMutableLogEvent.

@Test
public void testMutableLogEvent() throws Exception {
    final AbstractJacksonLayout layout = YamlLayout.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();
    Log4jLogEvent logEvent = LogEventFixtures.createLogEvent();
    final MutableLogEvent mutableEvent = new MutableLogEvent();
    mutableEvent.initFrom(logEvent);
    final String strLogEvent = layout.toSerializable(logEvent);
    final String strMutableEvent = layout.toSerializable(mutableEvent);
    assertEquals(strMutableEvent, strLogEvent, strMutableEvent);
}
Also used : KeyValuePair(org.apache.logging.log4j.core.util.KeyValuePair) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) AbstractJacksonLayout(org.apache.logging.log4j.jackson.AbstractJacksonLayout) MutableLogEvent(org.apache.logging.log4j.core.impl.MutableLogEvent) Test(org.junit.Test)

Aggregations

MutableLogEvent (org.apache.logging.log4j.core.impl.MutableLogEvent)11 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)6 Test (org.junit.Test)5 AbstractJacksonLayout (org.apache.logging.log4j.jackson.AbstractJacksonLayout)4 Message (org.apache.logging.log4j.message.Message)4 KeyValuePair (org.apache.logging.log4j.core.util.KeyValuePair)3 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Test (org.junit.jupiter.api.Test)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Date (java.util.Date)1 LogEvent (org.apache.logging.log4j.core.LogEvent)1 Log4jJsonObjectMapper (org.apache.logging.log4j.jackson.json.Log4jJsonObjectMapper)1 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)1 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)1 ReusableParameterizedMessage (org.apache.logging.log4j.message.ReusableParameterizedMessage)1