How to enable access logging for JBoss EAP 7/8?
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 7
- 8
Issue
- How to enable the access log in JBoss EAP7?
- How to enable friendly access log times in JBoss EAP7?
- How can I configure the access-log pattern in EAP7?
- Need to find the equivalent for
org.apache.catalina.valves.AccessLogValvefor Undertow in EAP 7 - How to enable the access log in JBoss EAP8?
- How can I configure the access-log pattern in EAP8?
Resolution
This solution is part of the [Master] Configuring Access Logs in Red Hat Middleware Products..
Configure inside the Undertow subsystem setting:
-
Add the following
<access-log>setting insidehost name="default-host"under the Undertow subsystem in your configuration file (e.g. instandalone.xml/standalone-full.xml/standalone-ha.xml/standalone-full-ha.xml, or the appropriate profile indomain.xml):<subsystem xmlns="urn:jboss:domain:undertow:3.1" statistics-enabled="true"> ... <server name="default-server"> <http-listener name="default" socket-binding="http" redirect-socket="https" record-request-start-time="true"/> <host name="default-host" alias="localhost"> <access-log pattern="%h %l %u %t "%r" %s %b "%{i,Referer}" "%{i,User-Agent}" Cookie: "%{i,COOKIE}" Set-Cookie: "%{o,SET-COOKIE}" SessionID: %S Thread: "%I" TimeTaken: %T"/> </host> </server> ... </subsystem> -
Also note that you need to set the
record-request-start-timeattribute totruefor the listener(http-listener,ajp-listenerandhttps-listenerwhich you are using) to log response time (%Din milliseconds or%Tin seconds) in access logging. See Access log pattern %D and %T (response time) prints "-" in Undertow in JBoss EAP 7 for details. -
To add these using the CLI the following commands could be used. If you are using
domainmode instead ofstandalonemode, you need to add the prefix/profile=<your-profile-name>to the each command:/subsystem=undertow/server=default-server/http-listener=default:write-attribute(name=record-request-start-time,value=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}\" Cookie: \"%{i,COOKIE}\" Set-Cookie: \"%{o,SET-COOKIE}\" SessionID: %S Thread: \"%I\" TimeTaken: %T") -
The access log file will be output as
access_log.logunder the JBoss log directory by default (underjboss.server.log.dirwhich is$JBOSS_HOME/standalone/log/directory by default for standalone mode).
You can specify a custom output directory through thedirectoryparameter. Also, you can customize the file name withprefixparameter (access_log.by default) andsuffixparameter (logby default). Note that if customizing the file name (via prefix and suffix parameters), any.separating the prefix and suffix should be included at the end of theprefixonly (for example, specifyprefix="custom_access." suffix="log"to output the file namecustom_access.log).
With the following example configuration, the access log file will be output ascustom_access.logunder/path/to/desired/directorydirectory:<access-log pattern="%h %l %u %t "%r" %s %b "%{i,Referer}" "%{i,User-Agent}" Cookie: "%{i,COOKIE}" Set-Cookie: "%{o,SET-COOKIE}" SessionID: %S Thread: "%I" TimeTaken: %T" directory="/path/to/desired/directory" prefix="custom_access." suffix="log" />You may also use the
relative-toparameter to make that custom directory relative to another. With the following example configuration, the access log file will be output ascustom_access.logunder$JBOSS_HOME/standalone/log/path/to/desired/directorydirectory:<access-log pattern="%h %l %u %t "%r" %s %b "%{i,Referer}" "%{i,User-Agent}" Cookie: "%{i,COOKIE}" Set-Cookie: "%{o,SET-COOKIE}" SessionID: %S Thread: "%I" TimeTaken: %T" directory="/path/to/desired/directory" prefix="custom_access." suffix="log" relative-to="jboss.server.log.dir"/> -
Note that the log file will not be created until after the first time a request completely processes on the server
-
If you want to dynamically enable/disable access-log then set
record-request-start-timeattribute totrueand take the restart (during a maintenance window) and then you can enable access-log as described earlier or disable it by removing the same dynamically./subsystem=undertow/server=default-server/host=default-host/setting=access-log:remove -
For more details refer to Content from wildscribe.github.io is not included.access log configuration and Content from undertow.io is not included.access log pattern format. The above pattern is "combined" one followed by Cookie header in request and Set-cookie header in response, session-id (
%S), thread name (%I), time taken in seconds (%T) (in seconds but it shows milliseconds after the decimal point like12.345). -
By default, the access logs are rotated daily. Note that log rotation occurs at the first log entry written after the date changes (= no log rotation happen if no log entry is written after the date changes).
For rotating different periods (= other than daily) or rotating by size, follow the instructions in Rotating Access Logs in JBoss EAP 7.x -
An example logging output with the above example configuration will be like the following:
127.0.0.1 - - [12/Mar/2020:16:46:40 +0900] "GET /example/ HTTP/1.1" 200 1181 "-" "curl/7.29.0" Cookie: "-" Set-Cookie: "JSESSIONID=ZIA-vcbvaIjC5Gf-bG8wvEv7CzBd-0GI7X3NCFAE.node1; path=/example" SessionID: ZIA-vcbvaIjC5Gf-bG8wvEv7CzBd-0GI7X3NCFAE Thread: "default task-3" TimeTaken: 0.011 127.0.0.1 - - [12/Mar/2020:16:46:41 +0900] "GET /example/ HTTP/1.1" 200 1349 "-" "curl/7.29.0" Cookie: "JSESSIONID=ZIA-vcbvaIjC5Gf-bG8wvEv7CzBd-0GI7X3NCFAE.node1" Set-Cookie: "-" SessionID: ZIA-vcbvaIjC5Gf-bG8wvEv7CzBd-0GI7X3NCFAE Thread: "default task-3" TimeTaken: 0.006
For Openshift Images:
By default, access logging for Undertow is disabled in the JBoss EAP for Openshift images.
-
Add the
ENABLE_ACCESS_LOGenvironment variable to the deployment config for an application pod. SetENABLE_ACCESS_LOG=trueto enable access logging. Remove the environment variable to disable access logging. The access log with%h %l %u %t %{i,X-Forwarded-Host} "%r" %s %bpattern will be logged to the console where it can be viewed withoc logs <pod-name>:06:38:15,067 INFO [io.undertow.accesslog] (default task-1) xxx.xxx.xxx.xxx- - [19/Mar/2021:06:38:15 +0000] - "GET /test/test HTTP/1.1" 200 6 -
If you want to apply a custom pattern such as
%Dand%T, it can be configured by mounting a custom script in ConfigMap instead ofENABLE_ACCESS_LOG. The custom script is available injboss-eap-7/eap72-openshift:1.2or later.$ cat extensions/postconfigure.sh #!/bin/sh echo "Executing postconfigure.sh" $JBOSS_HOME/bin/jboss-cli.sh --file=$JBOSS_HOME/extensions/extensions.cli $ cat extensions/extensions.cli embed-server --std-out=echo --server-config=standalone-openshift.xml batch /subsystem=undertow/server=default-server/http-listener=default:write-attribute(name=record-request-start-time,value=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}\" Cookie: \"%{i,COOKIE}\" Set-Cookie: \"%{o,SET-COOKIE}\" SessionID: %S Thread: \"%I\" TimeTaken: %T", use-server-log=true) run-batch quit $ oc create configmap jboss-cli --from-file=postconfigure.sh=extensions/postconfigure.sh --from-file=extensions.cli=extensions/extensions.cli $ oc set volume dc/<dc-name> --add --name=jboss-cli -m /opt/eap/extensions -t configmap --configmap-name=jboss-cli --default-mode='0755'The access log with custom pattern will be loged to the console by applying the custom script:
06:21:33,028 INFO [io.undertow.accesslog] (default task-1) xxx.xxx.xxx.xxx - - [19/Mar/2021:06:21:33 +0000] "GET /test/test HTTP/1.1" 200 6 "-" "curl/7.29.0" Cookie: "-" Set-Cookie: "-" SessionID: - Thread: "default task-1" TimeTaken: 0.002
Related Solutions
Diagnostic Steps
- For standalone mode Check
$JBOSS_HOME/standalone/log/access_log.logfile for access log details.
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.