aspose file tools*
The moose likes Other Open Source Projects and the fly likes How to get the timestamp in GMT format in Log4j.xml? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "How to get the timestamp in GMT format in Log4j.xml?" Watch "How to get the timestamp in GMT format in Log4j.xml?" New topic
Author

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

Gp From Pune
Greenhorn

Joined: May 06, 2009
Posts: 2
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

Joined: Jun 24, 2003
Posts: 3274
    
    5

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"/>


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Gp From Pune
Greenhorn

Joined: May 06, 2009
Posts: 2
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get the timestamp in GMT format in Log4j.xml?