Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic