Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get the timestamp in GMT format in Log4j.xml?

 
Gp From Pune
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a log4j.xml
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">



<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">



<appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">

<layout class="org.apache.log4j.PatternLayout">

<param name="ConversionPattern" value="%d (%F:%L) %-5p %c - %m%n"/>

</layout>

</appender>



<appender name="FileAppender" class="org.apache.log4j.RollingFileAppender">

<param name="File" value="opicsloader.log"/>

<param name="MaxFileSize" value="5242880"/>

<param name="MaxBackupIndex" value="15"/>

<layout class="org.apache.log4j.PatternLayout">

<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss.SSS 'GMT'Z}(%F:%L) %-5p %c - %m%n"/>

</layout>

</appender>



<category name="org.apache.commons.digester.Digester">

<priority value="INFO"/>

</category>



<root>

<priority value="INFO"/>

<appender-ref ref="FileAppender"/>

<appender-ref ref="ConsoleAppender"/>

</root>



</log4j:configuration>

Here I have a conversionpattern for RollingFileAppender class.
I have used the following format to get the date display in GMT format in logs but didn't get the date in GMT formt.
%d{yyyy-MM-dd HH:mm:ss.SSSZ}

%d{yyyy-MM-dd HH:mm:ss.SSS’Z’}

%d{yyyy-MM-dd HH:mm:ss.SSS ‘Z’}

%d{yyyy-MM-dd HH:mm:ss.SSS ‘z’}

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



Could you please help me out?
Thanks in advance.

Regards,
Gaurav

 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From Google I was told that the following should work, but I haven't tried it myself...

<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss}{GMT}Z%-5p [%t] %C{2} (%F:%L) - %m%n"/>
 
Gp From Pune
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks Martin....

I have tried that but no luck..........
I have tired so many option in %d of conversionpattern param of patternlayout of log4j.xml.

Could anyone please help me???
Its too urgent..
Thanks in advance guys..

Regards,
Gaurav
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic