use of org.apache.logging.log4j.core.time.MutableInstant in project logging-log4j2 by apache.
the class DatePatternConverter method getMutableInstant.
private MutableInstant getMutableInstant() {
if (Constants.ENABLE_THREADLOCALS) {
MutableInstant result = threadLocalMutableInstant.get();
if (result == null) {
result = new MutableInstant();
threadLocalMutableInstant.set(result);
}
return result;
}
return new MutableInstant();
}
use of org.apache.logging.log4j.core.time.MutableInstant in project logging-log4j2 by apache.
the class DatePatternConverterTest method testFormatDateStringBuilderIso8601WithPeriodMicroseconds.
@Test
public void testFormatDateStringBuilderIso8601WithPeriodMicroseconds() {
final String[] pattern = { FixedDateFormat.FixedFormat.ISO8601_PERIOD_MICROS.name(), "Z" };
final DatePatternConverter converter = DatePatternConverter.newInstance(pattern);
final StringBuilder sb = new StringBuilder();
MutableInstant instant = new MutableInstant();
instant.initFromEpochMilli(1577225134559L, // One microsecond
1000);
converter.format(instant, sb);
final String expected = "2019-12-24T22:05:34.559001";
assertEquals(expected, sb.toString());
}
use of org.apache.logging.log4j.core.time.MutableInstant in project logging-log4j2 by apache.
the class InstantAttributeConverterTest method testConvert01.
@Test
public void testConvert01() {
final MutableInstant instant = new MutableInstant();
instant.initFromEpochSecond(1234567, 89012);
final String converted = this.converter.convertToDatabaseColumn(instant);
assertNotNull("The converted value should not be null.", converted);
assertEquals("The converted value is not correct.", "1234567,89012", converted);
final Instant reversed = this.converter.convertToEntityAttribute(converted);
assertNotNull("The reversed value should not be null.", reversed);
assertEquals("epoch sec", 1234567, reversed.getEpochSecond());
assertEquals("nanoOfSecond", 89012, reversed.getNanoOfSecond());
}
use of org.apache.logging.log4j.core.time.MutableInstant in project logging-log4j2 by apache.
the class InstantAttributeConverter method convertToEntityAttribute.
@Override
public Instant convertToEntityAttribute(final String s) {
if (Strings.isEmpty(s)) {
return null;
}
int pos = s.indexOf(",");
long epochSecond = Long.parseLong(s.substring(0, pos));
int nanos = Integer.parseInt(s.substring(pos + 1, s.length()));
MutableInstant result = new MutableInstant();
result.initFromEpochSecond(epochSecond, nanos);
return result;
}
use of org.apache.logging.log4j.core.time.MutableInstant in project logging-log4j2 by apache.
the class LogEventEntityTest method testToImmutable_AbstractLogEventWrapperEntity.
@Test
public void testToImmutable_AbstractLogEventWrapperEntity() {
final LogEvent logEvent = new AbstractLogEventWrapperEntity() {
private static final long serialVersionUID = 2L;
@Override
public ContextStack getContextStack() {
return null;
}
@Override
public Level getLevel() {
return null;
}
@Override
public String getLoggerFqcn() {
return null;
}
@Override
public String getLoggerName() {
return null;
}
@Override
public Marker getMarker() {
return null;
}
@Override
public Message getMessage() {
return null;
}
@Override
public Instant getInstant() {
return new MutableInstant();
}
@Override
public long getNanoTime() {
return 0;
}
@Override
public StackTraceElement getSource() {
return null;
}
@Override
public long getThreadId() {
return 0;
}
@Override
public String getThreadName() {
return null;
}
@Override
public int getThreadPriority() {
return 0;
}
@Override
public Throwable getThrown() {
return null;
}
@Override
public ThrowableProxy getThrownProxy() {
return null;
}
@Override
public long getTimeMillis() {
return 0;
}
};
Assert.assertNotSame(logEvent, logEvent.toImmutable());
}
Aggregations