How can i format log4j time to specific timezone?

Bhavesh Shah :

Below is my log4j2 layout :

layout = %d{DATE} %-5p - %m%n.

It'll print time in log as -> 2019-05-28 11:48:36,977 INFO - Hello World.

Which is my system datetime(IST),but I want to print log datetime in GMT format.

is it possible to format timezone in log4j2?

ruhul :

Yes it is possible.

To format date time in GMT please consider

%d{yyyy-MM-dd:HH:mm:ss.SSS,GMT+0}

You can also change time zone by adding number after GMT for example:

%d{yyyy-MM-dd:HH:mm:ss.SSS,GMT+06}

for more check out this link: Log4J Layouts

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=100343&siteId=1