membersound membersound - 4 months ago 130
Java Question

How to log CXF webservice requests with log4j2?

I'd like to log all incoming and outgoing

CXF
requests to a specific logfile. But all I get with the following configuration is a console output. What is wrong here?

log4j2.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
</Console>

<RollingFile name="CXF" fileName="cxf.log">
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
</RollingFile>
</Appenders>
<Loggers>
<logger name="org.apache.cxf" additivity="false" level="info">
<AppenderRef ref="CXF"/>
</logger>
<logger name="org.apache.cxf.interceptor.LoggingInInterceptor" additivity="false" level="info">
<AppenderRef ref="CXF" />
</logger>
<logger name="org.apache.cxf.interceptor.LoggingOutInterceptor" additivity="false" level="info">
<AppenderRef ref="CXF" />
</logger>

<Root level="all">
<AppenderRef ref="CONSOLE" />
</Root>
</Loggers>
</Configuration>


src/main/resources/META-INF/cxf/org.apache.cxf.Logger:

org.apache.cxf.common.logging.Log4jLogger

Answer

As a workaround, I'm now using org.apache.cxf.common.logging.Slf4jLogger and the bridge dependency.

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>2.0</version>
    </dependency>
Comments