[ https://issues.apache.org/jira/browse/LOG4J2-3498?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17532239#comment-17532239 ]
Benjamin Tanguay commented on LOG4J2-3498: ------------------------------------------ I've updated the library to 2.17.2 in the test project. Results are the same. The project uses Java 11 to compile but I've run the jar on a Java 18 runtime and it fails in the same way. For OS, I've tried a RHEL 8 VM and Alpine via docker. The results are the same in both cases. Also, I don't know how the instant is generated in log4j2 but the following code populates the nano seconds properly on linux (and probably windows as well): {code:java} import java.time.Clock; import java.time.Duration; import java.time.Instant; class NanoTime { public static void main(String[] args) { Clock c = Clock.tick(Clock.systemUTC(), Duration.ofNanos(0L)); for (int i = 0; i < 2000; i++) { Instant instant = c.instant(); System.out.println(instant.toString() + " " + instant.getNano()); } } } {code} > Timestamp lacks micro and nano second precision on linux > -------------------------------------------------------- > > Key: LOG4J2-3498 > URL: https://issues.apache.org/jira/browse/LOG4J2-3498 > Project: Log4j 2 > Issue Type: Bug > Reporter: Benjamin Tanguay > Priority: Minor > > Generating a timestamp with micro and nano seconds defined fails when the > operating system is linux. Instead of having the required precision, the log > pads the micro and nano seconds with zeros. Testing it between some > developpers, the code works properly on Windows and Mac and only fails on > Linux machines. > Our team has tested this internally and it seems that the problem is linked > to a bad interaction between Linux and the library. We've tested with > different JDK versions and vendors and the problem remained the same. The > problem also works in the same way whether we use a JsonLayout or a > PatternLayout to output the timestamp in the log. > > {*}Expected{*}: > A timestamp with the form: "timestamp":"2022-05-04T17:53:43.914{*}123456{*}Z" > {*}Actual{*}: > A timestamp with the form: "timestamp":"2022-05-04T17:53:43.914{*}000000{*}Z" > > I created a small project to reproduce the issue. Notice the script demo.sh > that allows you to build an alpine image, execute the code in docker and > output the log in the console. > [https://github.com/BenjaminTanguay/log4j-low-timestamp-precision-linux-demo] > -- This message was sent by Atlassian Jira (v8.20.7#820007)