How to enable access logging for JBoss EAP 6?

Solution Verified - Updated -

Environment

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

Issue

  • Activate instant http request access logging to file for the web subsystem
  • Access logs not generating.
  • Convert this configuration from an earlier version

    <Valve className="org.apache.catalina.valves.AccessLogValve" 
                    prefix="localhost_access_log." suffix=".log"
                    pattern="common" directory="${jboss.server.log.dir}" 
                    resolveHosts="false" />
    
  • Access log file shows false2015-11-11

  • Create access logs with different name format.

Resolution


DISCLAIMER: Links contained herein to external website(s) are provided for convenience only. Red Hat has not reviewed the links and is not responsible for the content or its availability. The inclusion of any link to an external website does not imply endorsement by Red Hat of the website or their entities, products or services. You agree that Red Hat is not responsible or liable for any loss or expenses that may result due to your use of (or reliance on) the external site or content.


This solution is part of the [Master] Configuring Access Logs in Red Hat Middleware Products..

By default there is no web logging enabled. In JBoss 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>
                <!-- 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>
                <!--  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 TimeTaken: %T </param-value>
                -->
                <!-- combined + Session ID + Response time 
                <param-value>%h %l %u %t %r %s %b %{Referer}i %{User-Agent}i SessionID: %S TimeTaken: %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>

Note: This can be enabled/disabled by changing the above config and redeploying the application.

Via WebSubsystem

Run the following CLI commands standalone.xml. Prefix all commands with /profile=MYPROFILE for domain.xml. Restart the server for this to take effect.

    /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 %{Referer}i %{User-Agent}i Cookie: %{COOKIE}i Set-Cookie: %{SET-COOKIE}o SessionID: %S Thread: %I TimeTaken: %T ")
    /subsystem=web/virtual-server=default-host/configuration=access-log:write-attribute(name="prefix",value="access_log_")

Note Don't leave off the prefix because it will end up adding false.

This will result in:

    <access-log pattern="%h %l %u %t %r %s %b %{Referer}i %{User-Agent}i Cookie: %{COOKIE}i Set-Cookie: %{SET-COOKIE}o SessionID: %S Thread: %I TimeTaken: %T" prefix="access_log_"/>

By default, access logging is output under ${jboss.server.log.dir}/default-host i.e. under $JBOSS_HOME/standalone/log/default-home, but it's possible to change the directory:

    /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")

This will result in the following XML:

    <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">
        <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 Cookie: %{COOKIE}i Set-Cookie %{SET-COOKIE}o SessionID: %S Thread: %I TimeTaken: %T" prefix="access_log_">
                <directory path="${jboss.server.name}-accessLog" relative-to="my.log.dir" />
            </access-log>
        </virtual-server>
    </subsystem>

This would output access log under /mnt/log/jboss/my-access-log, please configure the following <directory> and <paths> setting. Leave off the directory settings if the default path is required.

Since JBoss Web is based on Apache Catalina, check AccessLogValvepage in Apache Tomcat documentation for more arguments to use.

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.

5 Comments

I am running JBoss in a container. I would like send the access logs to console/system log instead of directory as shown below. Is it possible ?

        <param>
            <param-name>directory</param-name>
            <param-value>${jboss.server.log.dir}</param-value>
        </param>

or
               <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" />

Hello, can you update for EAP 7 too? Thanks, Gianluca

thanks for the link to the new KCS, both you and Masanobu

Hello, can you check this KCS for EAP7?
https://access.redhat.com/solutions/2423311