WildFly 9 Access Logging

Andrew Arias picture Andrew Arias · Jan 5, 2016 · Viewed 8.5k times · Source

I am trying to set up access logging using WildFly 9 in Domain mode. I have found a few resources which suggest using something like this in the domain.xml file:

 <host name="default-host" alias="localhost">
     <location name="/" handler="welcome-content"/>
     <filter-ref name="server-header"/>
     <filter-ref name="x-powered-by-header"/>
     <access-log pattern="%A%t%h%l%u%r%s%b%T%I" directory="${jboss.server.log.dir}" prefix="access" suffix=".log"/>
 </host>

I then restarted wildfly, but no logging is occurring and there are no errors in the wildfly start up, so I am just banging my head against the wall. I would really appreciate any help that anyone can provide.

Also is there a way to register access logging using the cli in domain mode?

Answer

James R. Perkins picture James R. Perkins · Jan 6, 2016

There should be a way to add all resources in CLI for both domain mode and standalone. It's possible you're editing the wrong profile in the XML. Regardless using CLI is the preferred solution.

The first thing you need to know is which profile you're running under. You can determine by the server-group(s) running.

[domain@localhost:9990 /] /server-group=*:read-attribute(name=profile)
{
    "outcome" => "success",
    "result" => [
        {
            "address" => [("server-group" => "main-server-group")],
            "outcome" => "success",
            "result" => "full"
        },
        {
            "address" => [("server-group" => "other-server-group")],
            "outcome" => "success",
            "result" => "full-ha"
        }
    ]
}

We'll assume here we're using the main-server-group. You then need to add the access-log setting to the undertow subsystem.

/profile=full/subsystem=undertow/server=default-server/host=default-host/setting=access-log:add(pattern="%A%t%h%l%u%r%s%b%T%I", directory="${jboss.server.log.dir}", prefix=access, suffix=".log")

This will add access logging to all servers in that server-group. You will need to access a server via a web request before the log will be created. No restart or reload is required either.

One extra note too you can see what settings are available to the setting resource in undertow with the following command.

/profile=full/subsystem=undertow/server=default-server/host=default-host/setting=*:read-resource-description