Skip to content

Commit 66aa10c

Browse files
committed
Compare LogEvent by full instant time
Replace nano-of-millisecond comparison with a combined Instant-based time. The comparator now imports org.apache.logging.log4j.core.time.Instant and uses a new getTime(LogEvent) that adds instant.getEpochMillisecond() and instant.getNanoOfMillisecond() (returning a long) for ordering, instead of comparing only getNanoOfMillisecond(). Method renamed and return type adjusted accordingly.
1 parent ddd916e commit 66aa10c

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

microsphere-log4j2/src/main/java/io/microsphere/logging/log4j2/LogEventComparator.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.microsphere.logging.log4j2;
1818

1919
import org.apache.logging.log4j.core.LogEvent;
20+
import org.apache.logging.log4j.core.time.Instant;
2021

2122
import java.util.Comparator;
2223

@@ -39,10 +40,11 @@ private LogEventComparator() {
3940

4041
@Override
4142
public int compare(LogEvent o1, LogEvent o2) {
42-
return Long.compare(getNanoOfMillisecond(o1), getNanoOfMillisecond(o2));
43+
return Long.compare(getTime(o1), getTime(o2));
4344
}
4445

45-
private int getNanoOfMillisecond(LogEvent logEvent) {
46-
return logEvent.getInstant().getNanoOfMillisecond();
46+
private long getTime(LogEvent logEvent) {
47+
Instant instant = logEvent.getInstant();
48+
return instant.getEpochMillisecond() + instant.getNanoOfMillisecond();
4749
}
4850
}

0 commit comments

Comments
 (0)