How to enable access logging for JBoss EAP 6

Solution Verified - Updated -

Environment

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

Issue

  • How to activate http request access logging to file for the web subsystem?
  • How to enable access logs in JBoss EAP 6?
  • Access logs not generating in Domain Mode ? How to enable it?
  • Is JBoss Web logging not turned on by default? Is there some additional configuration that is needed to get the logging for the JBoss Web container?
  • How to configure access.log so that JBoss dumps logs instantly than later?
  • Migrating web application from JBoss 5.1.0 A.S to 6.3.0 EAP . Want to know how to configure below localhost access_log in JBoss EAP 6.3?
<Valve className="org.apache.catalina.valves.AccessLogValve" 
                prefix="localhost_access_log." suffix=".log"
                pattern="common" directory="${jboss.server.log.dir}" 
                resolveHosts="false" />
  • How to enable Access Logs in JBoss EAP 6 in domain mode. In older JBoss versions, we were able to enable access logs (tomcat logging) for debugging purposes. Is it possible to do so on this new version in domain mode?
  • How do you define the name for the localhost access log file to something other than false2015-11-11?
  • How to create the access log files with name localhost_access_log.YYYY-MM-DD.log, currently it is access-log.YYYY-MM-DD. How to add the suffix log to the filename in JBoss EAP 6.x?
  • We are not able to find how to configure http connector logging. There's no "access-log" entry in the virtual server config node in domain mode, so we don't know how to activate connector logging. How can this be done in domain mode?

Resolution

  • By default there is no web logging enabled. In EAP 6 access logging can be configured per web application, or by virtual-server of the web subsystem.

Per web application setting:

  • Configure AccessLogValve setting in WEB-INF/jboss-web.xml to enable access logging for a web application. For example:
<jboss-web>
    <valve>
        <class-name>org.apache.catalina.valves.AccessLogValve</class-name>
        <param>
            <param-name>prefix</param-name>
            <param-value>myapp_access_log.</param-value>
        </param>
        <param>
            <param-name>suffix</param-name>
            <param-value>.log</param-value>
        </param>
        <param>
            <param-name>fileDateFormat</param-name>
            <!-- You can use pattern letters defined in SimpleDateFormat.
                 This fileDateFormat setting affects to log rotation cycle
            -->
            <!-- default setting: daily -->
            <param-value>yyyy-MM-dd</param-value>
            <!-- hourly
            <param-value>yyyy-MM-dd.HH</param-value>
            -->
        </param>
        <param>
            <param-name>pattern</param-name>
            <!-- You can use constant text or replacement strings defined in 
                 http://docs.jboss.org/jbossweb/7.0.x/config/valve.html to pattern tokens.
            -->
            <!-- default setting: common (%h %l %u %t "%r" %s %b) -->
            <param-value>common</param-value>
            <!-- combined (%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i") 
            <param-value>combined</param-value>
            -->            
            <!-- combined + response time
            <param-value>%h %l %u %t %r %s %b %{Referer}i %{User-Agent}i %T</param-value>
            -->
            <!-- combined + Session ID + Response time 
            <param-value>%h %l %u %t %r %s %b %{Referer}i %{User-Agent}i %S %T</param-value>
            -->
        </param>
        <param>
            <param-name>directory</param-name>
            <param-value>${jboss.server.log.dir}</param-value>
        </param>
        <param>
            <param-name>resolveHosts</param-name>
            <param-value>false</param-value>
        </param>
    </valve>
</jboss-web>
  • This can be enabled/disabled by changing the above config and redeploying the application.

Web subsystem setting:

  • Add the following <access-log> setting inside <virtual-server> under web subsystem in standalone.xml or domain.xml
<access-log pattern='%h %l %u %t %r %s %b %{Referer}i %{User-Agent}i %S %T'/>
  • For example:
        <subsystem xmlns="urn:jboss:domain:web:1.2" default-virtual-server="default-host" native="false">
            <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
            <virtual-server name="default-host" enable-welcome-root="true">
                <alias name="localhost"/>
                <alias name="example.com"/>
                <access-log pattern='%h %l %u %t %r %s %b %{Referer}i %{User-Agent}i %S %T' prefix="access_log_"/>
            </virtual-server>
        </subsystem>
  • Due to a bug WFLY-1333, if the prefix attribute is not defined in the access-log definition, it will add false in front of date like the following. This will be fixed in the future release. Until the fix is included, please set prefix attribute explicitly as a workaround.
-rw-r----- 1  17714 Oct 29 12:04 false2013-10-29
-rw-r----- 1   9682 Oct 30 18:15 false2013-10-30
-rw-r----- 1  13417 Oct 31 16:08 false2013-10-31
-rw-r----- 1  53649 Nov  1 18:46 false2013-11-01
  • You can also configure the above <access-log> setting by the following CLI. Prefix with /profile=yourprofile for domain mode.
/subsystem=web/virtual-server=default-host/configuration=access-log:add
/subsystem=web/virtual-server=default-host/configuration=access-log:write-attribute(name="pattern",value="%h %l %u %t \\"%r\\" %s %b %S %T")
  • By default, access logging is output under ${jboss.server.log.dir}/default-host i.e. under $JBOSS_HOME/standalone/log/default-home. If you want to change the file path, please configure <directory> element with path and relative-to attributes inside <access-log> setting. For example, when you would like to output access log under $JBOSS_HOME/standalone/log, please configure the following <directory>:
        <subsystem xmlns="urn:jboss:domain:web:1.2" default-virtual-server="default-host" native="false">
            ...(snip)...
            <virtual-server name="default-host" enable-welcome-root="true">
                ...(snip)...
                <access-log pattern='%h %l %u %t %r %s %b %{Referer}i %{User-Agent}i %S %T'>
                    <directory path="./" relative-to="jboss.server.log.dir" /> 
                </access-log>
            </virtual-server>
        </subsystem>
  • You can also configure the above <access-log> setting by the following CLI:
        /subsystem=web/virtual-server=default-host/configuration=access-log:add
        /subsystem=web/virtual-server=default-host/configuration=access-log:write-attribute(name="pattern",value="%h %l %u %t \\"%r\\" %s %b %S %T")
        /subsystem=web/virtual-server=default-host/configuration=access-log/setting=directory:add
        /subsystem=web/virtual-server=default-host/configuration=access-log/setting=directory:write-attribute(name="path",value="./")
        /subsystem=web/virtual-server=default-host/configuration=access-log/setting=directory:write-attribute(name="relative-to",value="jboss.server.log.dir")
  • For example, when you would like to output access log under /mnt/log/jboss/my-access-log, please configure the following <directory> and <paths> setting:
        <paths>
            <path name="my.log.dir" path="/mnt/log/jboss"/>
        </paths>
        ...(snip)...
        <subsystem xmlns="urn:jboss:domain:web:1.2" default-virtual-server="default-host" native="false">
            ...(snip)...
            <virtual-server name="default-host" enable-welcome-root="true">
                ...(snip)...
                <access-log pattern='%h %l %u %t %r %s %b %{Referer}i %{User-Agent}i %S %T'>
                    <directory path="my-access-log" relative-to="my.log.dir" /> 
                </access-log>
            </virtual-server>
        </subsystem>
  • You can also configure the above <access-log> setting by the following CLI:
        /path=my.log.dir:add(path="/mnt/log/jboss")
        /subsystem=web/virtual-server=default-host/configuration=access-log:add
        /subsystem=web/virtual-server=default-host/configuration=access-log:write-attribute(name="pattern",value="%h %l %u %t \\"%r\\" %s %b %S %T")
        /subsystem=web/virtual-server=default-host/configuration=access-log/setting=directory:add
        /subsystem=web/virtual-server=default-host/configuration=access-log/setting=directory:write-attribute(name="path",value="my-access-log")
        /subsystem=web/virtual-server=default-host/configuration=access-log/setting=directory:write-attribute(name="relative-to",value="my.log.dir")
  • You can change folder name where the access log will be saved with the server name:
<server name="kkk" xmlns="urn:jboss:domain:1.3">
...
    <subsystem xmlns="urn:jboss:domain:web:1.2" default-virtual-server="default-host" native="false">
            <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
            <virtual-server name="default-host" enable-welcome-root="true">
                <alias name="localhost"/>
                <alias name="example.com"/>
               <access-log pattern='%h %l %u %t %r %s %b %{Referer}i %{User-Agent}i %S %T'>
                   <directory path="${jboss.server.name}-accessLog" relative-to="jboss.server.log.dir" />
                </access-log>
            </virtual-server>
        </subsystem>
  • Setting a global access log valve like this would require a restart or reload through CLI to be enabled. Note that the only attributes available for <access-log/> are pattern, rotate, prefix, extended, and resolve-hosts. suffix and fileDateFormat are not available.

Result folder name : kkk-accessLog/access.log

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.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.