Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-597

Use System.nanoTime() instead of System.currentTimeMillis() for LogEvent timestamp

    XMLWordPrintable

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 0.9.12
    • None
    • None

    Description

      Apparently the System.nanoTime() is better suited than System.currentTimeMillis() for the relative time measurements done in logback, plus hopefully the resolution is finer giving more reliable figures for small operations. Apparently the currentTimeMillis resolution is 15 ms under XP where the nanoTimer is much finer. Under OS X both have a resolution of 1 ms.

      As logback requires Java 5 where this is standard, it would be simple to make the switch.

      Note: http://www.techper.net/2008/08/10/systemcurrenttimemillis-systemnanotime-and-their-resolution/ lists that it may be relevant to create a factory for this instead of just hardlinking to the java runtime so it is possible to link to another time source:

      "A more robust timer with a 1msec resolution is LWJGL's Sys.getTime which uses TGT (time get time) on Windows and currentTimeMillis elsewhere."

      Attachments

        Activity

          People

            logback-dev Logback dev list
            ravn@runjva.com Thorbjoern Ravn Andersen
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: