Search in sources :

Example 16 with DummyNanoClock

use of org.apache.logging.log4j.core.time.internal.DummyNanoClock in project logging-log4j2 by apache.

the class JsonLayoutTest method testLayoutRingBufferEventReusableMessageWithCurlyBraces.

// Test for LOG4J2-2312 LOG4J2-2341
@Test
public void testLayoutRingBufferEventReusableMessageWithCurlyBraces() throws Exception {
    final boolean propertiesAsList = false;
    final AbstractJacksonLayout layout = JsonLayout.newBuilder().setLocationInfo(false).setProperties(false).setPropertiesAsList(propertiesAsList).setComplete(false).setCompact(true).setEventEol(false).setCharset(StandardCharsets.UTF_8).setIncludeStacktrace(true).build();
    Message message = ReusableMessageFactory.INSTANCE.newMessage("Testing {}", new TestObj());
    try {
        RingBufferLogEvent ringBufferEvent = new RingBufferLogEvent();
        ringBufferEvent.setValues(null, "a.B", null, "f.q.c.n", Level.DEBUG, message, null, new SortedArrayStringMap(), ThreadContext.EMPTY_STACK, 1L, "threadName", 1, null, new SystemClock(), new DummyNanoClock());
        final String str = layout.toSerializable(ringBufferEvent);
        final String expectedMessage = "Testing " + TestObj.TO_STRING_VALUE;
        assertThat(str, containsString("\"message\":\"" + expectedMessage + '"'));
        final Log4jLogEvent actual = new Log4jJsonObjectMapper(propertiesAsList, true, false, false).readValue(str, Log4jLogEvent.class);
        assertEquals(expectedMessage, actual.getMessage().getFormattedMessage());
    } finally {
        ReusableMessageFactory.release(message);
    }
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) ObjectMessage(org.apache.logging.log4j.message.ObjectMessage) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) Message(org.apache.logging.log4j.message.Message) SystemClock(org.apache.logging.log4j.core.time.internal.SystemClock) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) AbstractJacksonLayout(org.apache.logging.log4j.jackson.AbstractJacksonLayout) SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) DummyNanoClock(org.apache.logging.log4j.core.time.internal.DummyNanoClock) Log4jJsonObjectMapper(org.apache.logging.log4j.jackson.json.Log4jJsonObjectMapper) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RingBufferLogEvent(org.apache.logging.log4j.core.async.RingBufferLogEvent) Test(org.junit.Test)

Aggregations

DummyNanoClock (org.apache.logging.log4j.core.time.internal.DummyNanoClock)16 Test (org.junit.Test)11 Message (org.apache.logging.log4j.message.Message)9 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)9 Level (org.apache.logging.log4j.Level)8 Marker (org.apache.logging.log4j.Marker)8 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)8 FixedPreciseClock (org.apache.logging.log4j.core.time.internal.FixedPreciseClock)8 MutableThreadContextStack (org.apache.logging.log4j.spi.MutableThreadContextStack)8 Test (org.junit.jupiter.api.Test)5 SystemNanoClock (org.apache.logging.log4j.core.time.SystemNanoClock)4 StringMap (org.apache.logging.log4j.util.StringMap)4 BufferedReader (java.io.BufferedReader)3 File (java.io.File)3 FileReader (java.io.FileReader)3 RingBufferLogEvent (org.apache.logging.log4j.core.async.RingBufferLogEvent)2 Configuration (org.apache.logging.log4j.core.config.Configuration)2 NullConfiguration (org.apache.logging.log4j.core.config.NullConfiguration)2 ReusableMessageFactory (org.apache.logging.log4j.message.ReusableMessageFactory)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1