WildFly: Settings time-zone of log

1k Views Asked by At

in the EAR file of my JEE application I have a log4j.xml to define the logging for that application.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <appender name="fileAppender" class="org.apache.log4j.DailyRollingFileAppender">
        <param name="file" value="${jboss.server.log.dir}/licenseservice.log" />
        <param name="append" value="true" />
        <param name="datePattern" value="'.'yyyy-MM-dd" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} [%-5p] [%c:%L] - %m%n" />
        </layout>
    </appender>
    
    <root>
        <priority value="trace" />
        <appender-ref ref="fileAppender" />
    </root>
</log4j:configuration>

There are a few more entries in that file, but that them ignore for a moment. What I want to do is to change the time-zone of logged time to UTC. Somewhere I read you can do that by changing the pattern like this (if you want to have the time-zone of Germany):

%d{yyyy-MM-dd HH:mm:ss}{Europe/Berlin} [%-5p] [%c:%L] - %m%n

So my thought was that the following line should give me the UTC time:

%d{yyyy-MM-dd HH:mm:ss}{UTC} [%-5p] [%c:%L] - %m%n

But in the end both values didn't work.

Any ideas on that?

1

There are 1 best solutions below

4
On

Okay, I found my problem.

Just to change the pattern doesn't do the trick. You also have to change the class which parses the pattern from

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

to

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

Afterwards you will get a line like

2020-07-08 12:23:42 [INFO ] [<canonical-class-name>:<source-code-line] - <message>

in which the date and time are in UTC (in my case the local date time would have been 2020-07-08 14:23:42.