JDK-8175265 : Release Note: Precision of time stamps in java.util.logging.LogRecord has been increased
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.util.logging
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Delivered
  • Submitted: 2017-02-20
  • Updated: 2017-09-22
  • Resolved: 2017-02-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
Description
LogRecord now stores the event time in the form of a java.time.Instant. `XMLFormatter DTD` is upgraded to print the new higher time resolution.

In Java SE 9 `java.util.logging` is updated to use `java.time` instead of `System.currentTimeMillis()` and `java.util.Date`. This allows for higher time stamp precision in `LogRecord`.

As a consequence, the implementation of the methods `getMillis()` and `setMillis(long)` in `java.util.logging.LogRecord` has been changed to use `java.lang.Instant`, and the method `setMillis(long)` has been deprecated in favor of the new method `LogRecord.setInstant(java.time.Instant)`.
The `java.util.logging.SimpleFormatter` has been updated to pass a `java.time.ZonedDateTime` object instead of `java.util.Date` to `String.format`.
The `java.util.logging.XMLFormatter` has been updated to print a new optional `<nanos>` XML element after the `<millis>` element. The `<nanos>` element contains a nano seconds adjustment to the number of milliseconds printed in the `<millis>` element. The `XMLFormatter` will also print the full `java.time.Instant` in the `<date>` field, using the `java.time.format.DateTimeFormatter.ISO_INSTANT` formatter.

<b>Compatibility with previous releases:</b>

The `LogRecord` serial form, while remaining fully backward/forward compatible, now contains an additional serial <i>`nanoAdjustment`</i> field of type int, which corresponds to a nano seconds adjustment to the number of milliseconds contained in the serial <i>`millis`</i> field. If a `LogRecord` is serialized and transmitted to an application running on a previous release of the JDK, the application will simply see a `LogRecord` with a time truncated at the millisecond resolution. Similarly, if a `LogRecord` serialized by an application running on a previous release of the JDK, is transmitted to an application running on Java SE 9 or later, only the millisecond resolution will be available.

Applications that parse logs produced by the `XMLFormatter`, and which perform validation, may need to be upgraded with the newer version of the logger.dtd, available in the appendix A of the Logging Overview. In order to mitigate the compatibilty risks, the `XMLFormatter` class (and subclasses) can be configured to revert to the old XML format from Java SE 8 and before. See the `java.util.logging.XMLFormatter` API documentation for more details.

There could also be an issue if a subclass of `LogRecord` overrides `getMillis/setMillis` without calling the implementation of the super class. In that case, the event time as seen by the formatters and other classes may be wrong, as these have been updated to no longer call `getMillis()` but use `getInstant()` instead.