如何配置WildFly 8.2使用AccessLogHandler



我发现有一个处理程序io.undertow.server.handlers.accesslog.AccessLogHandler可以记录http访问。

但是我不能配置它,所以它将产生任何日志消息。

下面是我的standalone.xml中的代码片段:

<filter class-name="io.undertow.server.handlers.accesslog.AccessLogHandler" name="access-log-handler" module="io.undertow.core">
    <param name="formatString" value="common"/>
    <param name="accessLogReceiver" value="io.undertow.server.handlers.accesslog.JBossLoggingAccessLogReceiver"/>
</filter>

我的问题是如何配置处理程序,使它将开始产生日志消息。

不需要为访问日志添加自定义过滤器。您所需要的只是配置子系统本身的访问日志。下面是一个示例:

<host name="default-host" >
    <location name="/" handler="welcome-content">
     ....    
    <access-log />
</host>

将默认登录到前缀为access_log

的日志文件夹

您还可以自定义各种东西,从xsd:

<xs:attribute name="pattern" use="optional" type="xs:string" default="common"/>
<xs:attribute name="worker" use="optional" type="xs:string" default="default"/>
<xs:attribute name="directory" use="optional" type="xs:string" default="${jboss.server.log.dir}"/>
<xs:attribute name="relative-to" use="optional" type="xs:string" />
<xs:attribute name="prefix" use="optional" type="xs:string" default="access_log"/>
<xs:attribute name="suffix" use="optional" type="xs:string" default=".log"/>

我错过了添加这个xml片段(StackOverflow):

<host name="default-host" >
     .....
     <filter-ref name="access-log-handler"/>
</host>

然后我得到了这个:

Caused by: java.lang.NoSuchMethodException: io.undertow.server.handlers.accesslog.AccessLogHandler.<init>(io.undertow.server.HttpHandler)"}}

这是一个已知的错误:看看这个,或者这个

可以使用jboss-cli添加一个处理程序,看看standalone.xml是如何变化的:

/subsystem=undertow/configuration=filter/custom-filter=access-log-handler:add(class-name=io.undertow.server.handlers.accesslog.AccessLogHandler, module=io.undertow.core)
/subsystem=undertow/server=default-server/host=default-host/filter-ref=access-log-handler:add

最新更新