Starting with Java 9 and log4j 2.11.0 , you can get a timestamp even with nanoseconds.
Here are the special predefined patterns for getting a date or time with microseconds or nanoseconds:
- Output:
%d{ABSOLUTE_MICROS} Example output: 14:34:02,123456 - Output:
%d{ABSOLUTE_NANOS} Example output: 14:34:02,123456789 - Sample:
%d{DEFAULT_MICROS} Example output: 2012-11-02 14:34:02,123456 - Sample:
%d{DEFAULT_NANOS} Example output: 2012-11-02 14:34:02,123456789
If you need a more specific model, use the letter "nano-of-second" of pattern n instead of the letter "fractional part" S , for example %d{dd MMM yyyy HH:mm:ss,nnnn} to %d{dd MMM yyyy HH:mm:ss,nnnnnnnnn} , will give 02 Nov 2012 14:34:02,1234 to 02 Nov 2012 14:34:02,123456789 .
In your case, since you need milliseconds and microseconds, your template might be something like %d{dd/MM/yyyy HH:mm:ss,nnnnnn}
Log4j 2.11 adds limited timestamp support more accurately than milliseconds when running Java 9.
See https://logging.apache.org/log4j/2.x/manual/layouts.html for details
source share