Log4j 2.5 PatternLayout Nano timestamp not working

I am using PatternLayout in log4j 2.5. I also want to record timestamps of nanoseconds.

<Appenders>        
 <Console name="Console" target="SYSTEM_OUT">
        <PatternLayout pattern="nanotimestamp = %nano %n"/>
    </Console>
</Appenders>

And Java code

public static void main(String[] args) throws Exception {
    for(int = 0; i< 4; i++){
        logger.info("Hi");
        try {
            Thread.sleep(1000);
        }
    }
}

And the result:

nanotimestamp = 0 
nanotimestamp = 0 
nanotimestamp = 0 
nanotimestamp = 0 

Why is timestamp equal to 0? How can I get a nanosecond timestamp? Thanks.

+4
source share
1 answer

This is a bug in log4j 2.5.

Thanks for picking this up. I fixed it , and the fix will be in release 2.5.1.

+3
source

Source: https://habr.com/ru/post/1623467/


All Articles