How to customize date format pattern for access logging in JBoss EAP 8 / 7

Solution Verified - Updated

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 7.x

Issue

  • How do I customize date format pattern for access logging in JBoss EAP 7?
  • A default %t outputs date with a format like [01/Dec/2016:13:45:56 +0900]. I would like to change it like [2016-12-01 13:45:56.789] (with milliseconds but without timezone information). How can I configure this?
  • How do I increase time format precision in JBoss EAP access log?

Resolution

You can customize data format pattern by using %{time,xxx} with Content from docs.oracle.com is not included.SimpleDateFormat inside pattern attribute of <access-log> setting in undertow subsystem. (A default date format pattern is using [dd/MMM/yyyy:HH:mm:ss Z] internally.)

So, if you followed How to enable access logging for JBoss EAP 7? - Red Hat Customer Portal and just want to change date format like [2016-12-01 13:45:56.789], you can specifying [%{time,yyyy-MM-dd HH:mm:ss.SSS}] instead of %t. For example:

/subsystem=undertow/server=default-server/host=default-host/setting=access-log:add(pattern="%h %l %u [%{time,yyyy-MM-dd HH:mm:ss.SSS}] \"%r\" %s %b \"%{i,Referer}\" \"%{i,User-Agent}\" \"%{i,COOKIE}\" \"%{o,SET-COOKIE}\" %S \"%I\" %T")

Then, setting will change like the following:

<access-log pattern="%h %l %u [%{time,yyyy-MM-dd HH:mm:ss.SSS}] &quot;%r&quot; %s %b &quot;%{i,Referer}&quot; &quot;%{i,User-Agent}&quot; &quot;%{i,COOKIE}&quot; &quot;%{o,SET-COOKIE}&quot; %S &quot;%I&quot; %T"/>

By the way, note that the timestamp (%t) being logged by JBoss EAP 6.x (JBossWeb), JBoss EAP 7.x (Undertow) and Tomcat is not the time when a request was received but actually the time when the access logging was written at the completion of a request/response. See also this knowledge article "Discrepancy between Apache httpd log time and JBoss log time".

Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.