Skip to content

Commit d621b82

Browse files
author
Jay Katariya
committed
Feat(SystemClock): Added PreciseClock implementation to the system clock class, for the benefit of Java 8 users.
1 parent caffa21 commit d621b82

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

log4j-core/src/main/java/org/apache/logging/log4j/core/util/SystemClock.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@
1616
*/
1717
package org.apache.logging.log4j.core.util;
1818

19+
import java.time.Instant;
20+
import org.apache.logging.log4j.core.time.MutableInstant;
21+
import org.apache.logging.log4j.core.time.PreciseClock;
22+
1923
/**
2024
* Implementation of the {@code Clock} interface that returns the system time.
25+
* @since 2.25
2126
*/
22-
public final class SystemClock implements Clock {
27+
public final class SystemClock implements Clock, PreciseClock {
2328

2429
/**
2530
* Returns the system time.
@@ -29,4 +34,13 @@ public final class SystemClock implements Clock {
2934
public long currentTimeMillis() {
3035
return System.currentTimeMillis();
3136
}
37+
38+
/**
39+
* {@inheritDoc}
40+
*/
41+
@Override
42+
public void init(final MutableInstant mutableInstant) {
43+
final Instant instant = java.time.Clock.systemUTC().instant();
44+
mutableInstant.initFromEpochSecond(instant.getEpochSecond(), instant.getNano());
45+
}
3246
}

log4j-core/src/main/java/org/apache/logging/log4j/core/util/package-info.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Log4j 2 helper classes.
1919
*/
2020
@Export
21-
@Version("2.24.2")
21+
@Version("2.25.0")
2222
package org.apache.logging.log4j.core.util;
2323

2424
import org.osgi.annotation.bundle.Export;

0 commit comments

Comments
 (0)