Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8072645 java.util.logging should use java.time to get more precise time stamps
  3. JDK-8175265

Release Note: Precision of time stamps in java.util.logging.LogRecord has been increased



    • Type: Sub-task
    • Status: Closed
    • Priority: P3
    • Resolution: Delivered
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: core-libs


      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.




            dfuchs Daniel Fuchs
            dfuchs Daniel Fuchs
            0 Vote for this issue
            2 Start watching this issue