Advertise with us

Our eBooks

How do you configure WildFly / JBoss to enable HTTP logging ?

WildFly users

WildFly uses Undertow as Web server, which has deprecated the element Valve used in former Tomcat Web Server. You can still monitor HTTP logging by adding a Filter to your configuration as in this example:

<host name="default-host" >
     <filter-ref name="http-dumper"/>
    <filter name="http-dumper" class-name="io.undertow.server.handlers.RequestDumpingHandler" module="io.undertow.core" />

 You can add the Filter to your configuration using the following CLI command:

/subsystem=undertow/configuration=filter/custom-filter=http-dumper:add(class-name="io.undertow.server.handlers.RequestDumpingHandler",  module="io.undertow.core")

The RequestDumpingHandler filter will produce a verbose output, therefore it's recommended not to use it in production to avoid performance issues.

On the other hand, if you just want to keep track of the access-log of your server then you have to enable the access-log setting of your Host as follows:

add(pattern="%h %t \"%r\" %s \"%{i,User-Agent}\"", use-server-log=false)

 This reflects in the following configuration:

<host name="default-host" alias="localhost">
      <location name="/" handler="welcome-content"/>
      <access-log pattern="%h %t &quot;%r&quot; %s &quot;%{i,User-Agent}&quot;" use-server-log="false"/>
       <http-invoker security-realm="ApplicationRealm"/>

 As you can see, we have set the property "use-server-log" to false so that Undertow writes logs in a separate file named access_log.log, in the configuration/log folder:

~/jboss/wildfly-15.0.0.Final/standalone/log: ls -al
-rw-rw-r--. 1 wildfly wildfly  62997 Jan 17 10:39 access_log.log
-rw-rw-r--. 1 wildfly wildfly      0 Dec 17 15:59 audit.log
-rw-rw-r--. 1 wildfly wildfly 589363 Jan 17 10:38 server.log

 If set to "true", then the logs will be merged into the server.log file:

2019-01-17 10:37:22,968 INFO  [io.undertow.accesslog] (default task-16) [17/Jan/2019:10:37:22 +0100] "GET /api/v1/services?resourceVersion=0 HTTP/1.1" 404 "kube-proxy/v1.4.5 (linux/amd64) kubernetes/5a0a696"
2019-01-17 10:37:22,974 INFO  [io.undertow.accesslog] (default task-16) [17/Jan/2019:10:37:22 +0100] "GET /api/v1/services?resourceVersion=0 HTTP/1.1" 404 "kubelet/v1.4.5 (linux/amd64) kubernetes/5a0a696"
2019-01-17 10:37:22,974 INFO  [io.undertow.accesslog] (default task-15) [17/Jan/2019:10:37:22 +0100] "GET /api/v1/nodes? HTTP/1.1" 404 "kubelet/v1.4.5 (linux/amd64) kubernetes/5a0a696"
2019-01-17 10:37:23,095 INFO  [io.undertow.accesslog] (default I/O-3) [17/Jan/2019:10:37:23 +0100] "PATCH /api/v1/namespaces/default/events/ HTTP/1.1" 501 "kubelet/v1.4.5 (linux/amd64) kubernetes/5a0a696"
2019-01-17 10:37:23,293 INFO  [io.undertow.accesslog] (default I/O-3) [17/Jan/2019:10:37:23 +0100] "PATCH /api/v1/namespaces/default/events/ HTTP/1.1" 501 "kubelet/v1.4.5 (linux/amd64) kubernetes/5a0a696"

 JBoss AS 7 / JBoss EAP 6 users

To enable HTTP logging, you need to go to the deploy/jbossweb-tomcat55.sar directory. There you will see the server.xml file, to which you'll need to add the following valve definition:

<Valve className="org.apache.catalina.valves.FastCommonAccessLogValve"
           prefix="localhost_access_log." suffix=".log"
           pattern="common" directory="${jboss.server.home.dir}/log"
           resolveHosts="false" />

A Valve element represents a component that will be inserted into the request processing pipeline for the associated Catalina container. The Access Log Valve creates log files in the same format as those created by standard web servers. These logs can later be analyzed by standard log analysis tools to track page hit counts, user session activity, and so on. The files produces by this Valve are rolled over nightly at midnight.

Once you've restarted the server, Tomcat will create an access log.

© 2021 All Rights Reserved.

Please publish modules in offcanvas position.