Skip to content

Commit

Permalink
Feat(SystemClock): Added PreciseClock implementation to the system c…
Browse files Browse the repository at this point in the history
…lock class, for the benefit of Java 8 users. (#3217)

Added PreciseClock implementation to the system clock class, for the benefit of Java 8 users.

Co-authored-by: Jay Katariya <[email protected]>
Co-authored-by: Piotr P. Karwasz <[email protected]>
  • Loading branch information
3 people authored Jan 13, 2025
1 parent e71820a commit 7f81b51
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 358 deletions.
1 change: 0 additions & 1 deletion log4j-core-java9/src/assembly/java9.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<include>org/apache/logging/log4j/core/jackson/Log4jStackTraceElementDeserializer.class</include>
<include>org/apache/logging/log4j/core/jackson/StackTraceElementMixIn.class</include>
<include>org/apache/logging/log4j/core/util/internal/UnsafeUtil*.class</include>
<include>org/apache/logging/log4j/core/util/SystemClock.class</include>
</includes>
</fileSet>
</fileSets>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
*/
package org.apache.logging.log4j.core.util;

import java.time.Instant;
import org.apache.logging.log4j.core.time.MutableInstant;
import org.apache.logging.log4j.core.time.PreciseClock;

/**
* Implementation of the {@code Clock} interface that returns the system time.
*/
public final class SystemClock implements Clock {
public final class SystemClock implements Clock, PreciseClock {

/**
* Returns the system time.
Expand All @@ -29,4 +33,10 @@ public final class SystemClock implements Clock {
public long currentTimeMillis() {
return System.currentTimeMillis();
}

@Override
public void init(final MutableInstant mutableInstant) {
final Instant instant = java.time.Clock.systemUTC().instant();
mutableInstant.initFromEpochSecond(instant.getEpochSecond(), instant.getNano());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Log4j 2 helper classes.
*/
@Export
@Version("2.24.2")
@Version("2.25.0")
package org.apache.logging.log4j.core.util;

import org.osgi.annotation.bundle.Export;
Expand Down
Loading

0 comments on commit 7f81b51

Please sign in to comment.