Reputation: 81
access_log in wildfly logs the entries with the following predefined date format, which is produced by %t:
[22/Oct/2019:14:28:36 +0300]
However, I would like to change that to be as below:
[22/10/2019 14:28:36.345]
I have tried to change the pattern in standalone xml file as below:
<access-log pattern="%{dd/MMM/yyyy:HH:mm:ss Z}t %t %h %l %u "%r"s %s %b "%{i,Referer}" "%{i,User-Agent}""/>
However, the following is being logged instead:
%{dd/MMM/yyyy:HH:mm:ss Z}t [22/Oct/2019:14:28:36 +0300] 127.0.0.1 - - "GET /favicon.ico HTTP/1.1"s 302 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36"
How can I format the date properly?
I use wildfly-10.1.0. I have also tried the format below, that can be used for the apache access logs: But without any success.
There are other similar questions online, but have not been answered.
Upvotes: 3
Views: 3110
Reputation: 24812
The pattern used in the access log configuration is very limited and only recognizes these variables, where the date format isn't customizable as far as I know.
You should however be able to have the desired date format by delegating logging to the logging subsystem which accepts more complex formats :
In the undertow subsystem configuration, remove the date from the pattern and add the use-server-log
attribute :
<access-log pattern="%t %h %l %u "%r"s %s %b "%{i,Referer}" "%{i,User-Agent}"" use-server-log="true"/>
In the logging subsystem, define a logger which will catch your access logs and an associated handler using a formatter that will display the logs with the desired date format :
<periodic-rotating-file-handler name="ACCESS" autoflush="true">
<formatter>
<named-formatter name="%d{dd/MMM/yyyy:HH:mm:ss Z} %s"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="access.log"/>
<suffix value=".yyyy-MM-dd"/>
<append value="true"/>
</periodic-rotating-file-handler>
[...]
<logger category="io.undertow.accesslog" use-parent-handlers="false">
<handlers>
<handler name="ACCESS"/>
</handlers>
</logger>
My answer is largely based on this other answer which details how to set up access log rotation.
Upvotes: 1
Reputation: 81
Following a lot of troubleshooting, I have finally found the answer, which might be helpful to other people as well:
It is by adding the word 'time' as another argument in the formatter. As below:
<access-log pattern="[%{time,dd/MM/yyyy HH:mm:ss.SSS}] %h %l %u "%r" %s %b "%{i,Referer}" "%{i,User-Agent}""/>
Upvotes: 5