EAP 7 access-log rotates to a new file name with an incorrect date string when the rotation happens after restaring

Solution Unverified - Updated

Environment

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

Issue

  • EAP 7 access-log rotates to a new file name with an incorrect date string when the rotation happens after restaring.
  • For example, if the access-log rotation happened after restarting JBoss instance at 2018/04/22, access_log for 2018/04/21 would be rotated to access_log.2018-04-22.log and access_log for 2018/04/22 would be rotated to access_log.2018-04-22-1.log:
$ ls -l standalone/log/access_log*
-rw-rw-r--. 1 <user> <group> 69 Apr 20  2018 standalone/log/access_log.2018-04-20.log
-rw-rw-r--. 1 <user> <group> 69 Apr 22  2018 standalone/log/access_log.2018-04-22-1.log // this should be access_log.2018-04-22.log
-rw-rw-r--. 1 <user> <group> 69 Apr 21  2018 standalone/log/access_log.2018-04-22.log // this should be access_log.2018-04-21.log
-rw-rw-r--. 1 <user> <group> 69 Apr 23  2018 standalone/log/access_log.log

Resolution

The following JIRAs are raised to improve the behavior in the future release of JBoss EAP:

Until it's fixed, you can workaround this issue by enabling use-server-log option in <access-log> and using the rotation feature provided by logging subsystem. (Please also refer to this knowledge article). For example:

# Configure `<access-log>` with setting `use-server-log` attribute to true:
/subsystem=undertow/server=default-server/host=default-host/setting=access-log:add(pattern="%h %l %u %t \"%r\" %s %b \"%{i,Referer}\" \"%{i,User-Agent}\" \"%{i,COOKIE}\" \"%{o,SET-COOKIE}\" %S \"%I\" %T")
/subsystem=undertow/server=default-server/host=default-host/setting=access-log:write-attribute(name=use-server-log, value=true)
/subsystem=undertow/server=default-server/http-listener=default:write-attribute(name=record-request-start-time,value=true)

# Configure a custom handler for access logging in logging subsystem: 
/subsystem=logging/pattern-formatter=access-log-formatter:add(pattern="%s%n")
/subsystem=logging/periodic-rotating-file-handler=access-log:add(autoflush=true, append=true, named-formatter=access-log-formatter, suffix=".yyyy-MM-dd", file={path=access_log.log, relative-to=jboss.server.log.dir})
/subsystem=logging/logger=io.undertow.accesslog:add(handlers=[access-log], use-parent-handlers=false)

# Reload
:reload
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.