Thursday, December 6, 2018

How to enable HTTP access logs in Red Hat JBoss EAP 7.x

Add the following highlighted  setting inside host name="default-host" under Undertow subsystem in profile you are using.
e.g. It would be in one of the followings depending on the profile you have configured in your application.

  1. standalone-ha.xml: Default profile with clustering capabilities
  2. standalone-full-ha.xml: Full profile with clustering capabilities
  3. standalone-full.xml: Support of Java EE Full-Profile and all server capabilities without clustering
  4. standalone.xml: Support of Java EE Web-Profile plus some extensions like RESTFul Web Services and support for EJB3 remote invocations
 <subsystem xmlns="urn:jboss:domain:undertow:4.0">  
      .....  
      <server name="default-server">  
           <http-listener name="default" socket-binding="http" record-request-start-time="true" redirect-socket="https" enable-http2="true"/>  
           <https-listener name="https" socket-binding="https" record-request-start-time="true" security-realm="ApplicationRealm" enable-http2="true"/>  
           <host name="default-host" alias="localhost">  
                <access-log pattern="%h %l %u %t &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" directory="/accesslog" relative-to="jboss.server.log.dir"/>  
                <filter-ref name="server-header"/>  
                <filter-ref name="x-powered-by-header"/>  
                <http-invoker security-realm="ApplicationRealm"/>  
           </host>  
      </server>  
      .....  
 </subsystem>  


Also note that you need to set record-request-start-time attribute to true for the listener(http-listener, ajp-listener and https-listener which you are using) to log response time (%D in milliseconds or %T in seconds) in access logging

This will be logged to the JBoss log directory by default. You may specify a custom directory through the directory parameter. You may also add the relative-to="XXXXX" parameter to make that custom directory relative to another.

Also note that you need to set record-request-start-time attribute to true for the listener(http-listener, ajp-listener and https-listener which you are using) to log response time (%D in milliseconds or %T in seconds) in access logging

This will be logged to the JBoss log directory by default. You may specify a custom directory through the directory parameter. You may also add the relative-to parameter to make that custom directory relative to another.

Find below more details for access log pattern used above;

  • %a - Remote IP address
  • %A - Local IP address
  • %b - Bytes sent, excluding HTTP headers, or '-' if no bytes were sent
  • %B - Bytes sent, excluding HTTP headers
  • %h - Remote host name
  • %H - Request protocol
  • %l - Remote logical username from identd (always returns '-')
  • %m - Request method
  • %p - Local port
  • %q - Query string (excluding the '?' character)
  • %r - First line of the request
  • %s - HTTP status code of the response
  • %t - Date and time, in Common Log Format format
  • %u - Remote user that was authenticated
  • %U - Requested URL path
  • %v - Local server name
  • %D - Time taken to process the request, in millis
  • %T - Time taken to process the request, in seconds
  • %I - current Request thread name (can compare later with stacktraces)


In addition, the caller can specify one of the following aliases for commonly utilized patterns:

  • common - %h %l %u %t "%r" %s %b
  • combined - %h %l %u %t "%r" %s %b "%{i,Referer}" "%{i,User-Agent}"

There is also support to write information from the cookie, incoming header, or the session
It is modeled after the apache syntax:

  • %{i,xxx} for incoming headers
  • %{o,xxx} for outgoing response headers
  • %{c,xxx} for a specific cookie
  • %{r,xxx} xxx is an attribute in the ServletRequest
  • %{s,xxx} xxx is an attribute in the HttpSession