Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i format log4j time to specific timezone?

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?

like image 816
Bhavesh Shah Avatar asked Sep 14 '25 05:09

Bhavesh Shah


1 Answers

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

like image 186
MD Ruhul Amin Avatar answered Sep 15 '25 19:09

MD Ruhul Amin