Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

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

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

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



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



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

<priority value="INFO"/>



<priority value="INFO"/>

<appender-ref ref="FileAppender"/>

<appender-ref ref="ConsoleAppender"/>



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.


Posts: 3281
Mac OS X Eclipse IDE Java
  • 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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..

Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic