Skip to content

Commit b147ca3

Browse files
Jay Katariyajaykataria1111
Jay Katariya
authored andcommitted
Feat(SystemClock): Added PreciseClock implementation to the system clock class, for the benefit of Java 8 users.
1 parent 0f48f60 commit b147ca3

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-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;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="https://logging.apache.org/xml/ns"
4+
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
5+
type="changed">
6+
<issue id="3217" link="https://github.com/apache/logging-log4j2/pull/3217"/>
7+
<description format="asciidoc">Currently Java 8 users do not have access to timestamps with sub-millisecond precision.
8+
This change moves the SystemClock implementation from log4j-core-java9 to log4j-core, overriding the current one, so that java 8 users can benefit from it.
9+
</description>
10+
</entry>

0 commit comments

Comments
 (0)