title: Log4j2: How do I get timestamps that actually have nanosecond precision?
body: <p>In <a href="https://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout" rel="nofollow noreferrer">https://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout</a>, it described how to format the log timestamp with up to nanosecond precision.
  Further, in <a href="http://logging.apache.org/log4j/2.x/manual/configuration.html#SystemProperties" rel="nofollow noreferrer">http://logging.apache.org/log4j/2.x/manual/configuration.html#SystemProperties</a>, it is said that the default time stamp is taken from <code>System.getCurrentTimeMillis()</code> and that if you want a different clock, you should set the property <code>log4j2.clock</code> in <code>log4j2.component.properties</code> to the fully qualified class name of a class implementing <code>org.apache.logging.log4j.core.util.Clock</code>.
  Looking in <a href="https://logging.apache.org/log4j/2.x/log4j-core/apidocs/index.html" rel="nofollow noreferrer">https://logging.apache.org/log4j/2.x/log4j-core/apidocs/index.html</a>, I see that said interface allows only millisecond precision, but it has a sub-interface <code>org.apache.logging.log4j.core.time.PreciseClock</code> that allows for nanosecond precision. I have implemented a class</p>
  <pre><code>package my.package;
  import java.time.Instant;
  import org.apache.logging.log4j.core.time.MutableInstant;
  import org.apache.logging.log4j.core.time.PreciseClock;
  
  /**
   * Provides the current time up to nanosecond precision, as supported by the platform.
   * Note that most current platforms provide only microsecond precision.
   */
  public class NanoSecondClock implements PreciseClock {
      /**
       * Returns the time in milliseconds since the epoch.
       * @return the time in milliseconds since the epoch.
       */
      public long currentTimeMillis(){return System.currentTimeMillis();}
      /**
       * Initializes the specified instant with time information as accurate as available on this platform.
       * @param mutableInstant The container to be initialized with the accurate time information.
       */
      public void init(MutableInstant mutableInstant){
          Instant now=Instant.now();
          mutableInstant.initFromEpochSecond(now.getEpochSecond(),now.getNano());
      }
  }
  </code></pre>
  <p>This class provides both millisecond and nanosecond precision as it must to implement the interface. I have set the above mentioned property to that class.
  Now, in my logs I see only millisecond precision timestamps, even though I have tested that my platform supports microsecond precision in <code>Instant.now()</code>.</p>
  <p>Did I overlook something?</p>