Skip to content
Advertisement

How to format log4j timestamp with nanoseconds and timezone?

I want to achieve a timestamp that has nanoseconds and time zone difference, example:

2021-11-30 22:21:41.829798+02:00

I failed with variations like:

%d{yyyy-MM-dd HH:mm:ss.nnnnnnXXX}

Dependency:

<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.11.0</version>

Is that supported with log4j and if so how can I achieve that?

thanks.

Advertisement

Answer

I was able to find an obvious solution 🙂

%d{yyyy-MM-dd HH:mm:ss.nnnnnn}%d{XXX}

I separated the timestamp with nanos from the timezone itself and it worked.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement