开发者

How to enable logging of HTTP headers via log4j

I am trying to enable logging of incoming HTTP headers on my server which uses Axis2, is there a way to do it via l开发者_如何学运维og4j?


Axis2 uses Apache Commons Logging, a pluggable logging API. Now the question is: which logging library does your server use? If it's log4j, then you probably can make it log the Axis2 traffic — try setting

log4j.logger.org.apache.axis2.transport.http.server.wire=DEBUG

in the log4j.properties file of the application server.

If your server uses other lib, however, redirecting axis output to log4j may involve playing with classloaders as described in Commons Logging FAQ — so that Commons Logging and Log4j are loaded by the same classloader, you'll need to deploy both libraries with your EAR and reverse classloading policy to "parent last". Chances are other libraries from your application won't run with this setting.


I know it is old post, but I would like to share my solution to help other as I just faced the same case recently. I have configured the following in log4j.xml

<appender name="fileout" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="file" value="/soapLog/axis2.log" />
    <param name="DatePattern" value="'.'yyyy-MM-dd" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="[%p] %m%n" />
    </layout>

</appender>
<logger name="org.apache.axis2.enterprise">
    <level value="debug" />
    <appender-ref ref="fileout" />
</logger>
<logger name="de.hunsicker.jalopy.io">
    <level value="debug" />
    <appender-ref ref="fileout" />
</logger>
<logger name="httpclient.wire">
    <level value="debug" />
    <appender-ref ref="fileout" />
</logger>
<logger name="org.apache.commons.httpclient">
    <level value="debug" />
    <appender-ref ref="fileout" />
</logger>
<logger name="org.apache.axis2.transport.http.server.wire">
    <level value="debug" />
    <appender-ref ref="fileout" />
</logger>

Hope this may help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜