Skip to content
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

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

*/
public final class SystemClock implements Clock {
public final class SystemClock implements Clock, PreciseClock {

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

/**
* {@inheritDoc}
*/
Comment on lines +38 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I find {@inheritDoc} a little bit useless, since IDEs will look at the Javadoc of the parent class/implemented interface anyway, if the Javadoc is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
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
10 changes: 10 additions & 0 deletions src/changelog/.2.x.x/3217_precise_clock.xml
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>
Loading