Search in sources :

Example 16 with MutableInstant

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

the class JsonTemplateLayoutTest method createLogEventAtInstant.

private static LogEvent createLogEventAtInstant(final String formattedInstant) {
    final SimpleMessage message = new SimpleMessage("LogEvent at instant " + formattedInstant);
    final long instantEpochMillis = Instant.parse(formattedInstant).toEpochMilli();
    final MutableInstant instant = new MutableInstant();
    instant.initFromEpochMilli(instantEpochMillis, 0);
    return Log4jLogEvent.newBuilder().setLoggerName(LOGGER_NAME).setMessage(message).setInstant(instant).build();
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) MutableInstant(org.apache.logging.log4j.core.time.MutableInstant)

Aggregations

MutableInstant (org.apache.logging.log4j.core.time.MutableInstant)16 LogEvent (org.apache.logging.log4j.core.LogEvent)3 Test (org.junit.jupiter.api.Test)3 Instant (java.time.Instant)2 TemporalAccessor (java.time.temporal.TemporalAccessor)2 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)2 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)2 Test (org.junit.Test)2 Benchmark (org.openjdk.jmh.annotations.Benchmark)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 MappingIterator (com.fasterxml.jackson.databind.MappingIterator)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PrintStream (java.io.PrintStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 BigDecimal (java.math.BigDecimal)1 ServerSocket (java.net.ServerSocket)1