-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat(SystemClock): Added PreciseClock implementation to the system clock class, for the benefit of Java 8 users. #3217
base: 2.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,15 @@ | |
*/ | ||
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. | ||
* @since 2.25 | ||
*/ | ||
public final class SystemClock implements Clock { | ||
public final class SystemClock implements Clock, PreciseClock { | ||
|
||
/** | ||
* Returns the system time. | ||
|
@@ -29,4 +34,13 @@ public final class SystemClock implements Clock { | |
public long currentTimeMillis() { | ||
return System.currentTimeMillis(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
Comment on lines
+38
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally I find There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, will remove this too! |
||
@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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="https://logging.apache.org/xml/ns" | ||
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd" | ||
type="changed"> | ||
<issue id="3217" link="https://github.com/apache/logging-log4j2/pull/3217"/> | ||
<description format="asciidoc">Currently Java 8 users do not have access to timestamps with sub-millisecond precision. | ||
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. | ||
</description> | ||
</entry> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class itself is older, so we should remove the
@since
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!