0

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?

Grizzly
  • 45
  • 9

1 Answers1

0

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.

Grizzly
  • 45
  • 9
  • See here for more information: https://docs.jboss.org/jbossas/javadoc/7.1.2.Final/org/apache/log4j/EnhancedPatternLayout.html – Grizzly Jul 08 '20 at 12:36
  • In addition you also can modify the time-zone of the server.log. In that case you go to your configuration file (e.g. standalone-full.xml) and look for the tag. There a should be used. Within the pattern the timestamp might look like ```%d{HH:mm:ss,SSS}```. Here you can add the time zone like ```%z{UTC}%d{HH:mm:ss,SSS}```. See also: https://docs.wildfly.org/15/Admin_Guide.html#pattern-formatter – Grizzly Jul 08 '20 at 12:45
  • Instead of modifying the configuration directly you also can use the management console: http://:9990/console/index.html#logging-configuration Go to ```Formatter```. You should be able to see the ```COLOR-PATTERN``` (used for the console) and the ```PATTERN```. Modify both like described in my previous comment. – Grizzly Jul 08 '20 at 12:49
  • Last, but not least: It seems that you can't modify the time-zone of your timestamp in your access.log files (also the good news is that the time-zone will always be printed there): https://kb.novaordis.com/index.php/Undertow_WildFly_Subsystem_Configuration_-_access-log#Log_Patterns – Grizzly Jul 08 '20 at 12:57