Cxf incoming and outgoing messages in a separate log file

I looked through all the posts but did not find a clear answer to this question.

How do I configure logging to log inbound and outbound CXF messages?

I have the following setup.

  • Org.apache.cxf.Logger file with

    org.apache.cxf.common.logging.Log4jLogger
    
  • applicationContext.xml has the following (this sounds silly, but this is the only place for interceptors I could receive messages)

    <bean id="abstractLoggingInterceptor" abstract="true">
    <property name="prettyLogging" value="true"/>
    </bean>
    <bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor"
    parent="abstractLoggingInterceptor"/>
    <bean id="loggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"
    parent="abstractLoggingInterceptor"/>
    
    <cxf:bus>
    <cxf:inInterceptors>
    <ref bean="loggingInInterceptor"/>
    </cxf:inInterceptors>
    <cxf:outInterceptors>
    <ref bean="loggingOutInterceptor"/>
    </cxf:outInterceptors>
    <cxf:outFaultInterceptors>
    <ref bean="loggingOutInterceptor"/>
    </cxf:outFaultInterceptors>
    <cxf:inFaultInterceptors>
    <ref bean="loggingInInterceptor"/>
    </cxf:inFaultInterceptors>
    </cxf:bus>
    

I tried to follow these instructions with slf4j and with log4j, but the only output I get to the file is the application log message. I see incoming and outgoing messages on my console.

Can I get something like logback.xml for me, so I separate application logs and message logs. Example: http://www.wolfe.id.au/2011/05/20/apache-cxf-logging/

.

1: org.apache.cxf.common.logging.Log4jLogger log4j.xml. , INFO.

<appender name="RSLOGFILE" class="org.apache.log4j.RollingFileAppender">
<param name="file" value="${project.basedir}/logs/cxf_inout_messages.log"/>
<param name="MaxFileSize" value="100KB"/>
<!-- Keep one backup file -->
<param name="MaxBackupIndex" value="1"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- Print the date in ISO 8601 format -->
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<logger name="org.apache.cxf">
<level value="ERROR"/>
<appender-ref ref="RSLOGFILE"/>
</logger>
+5
1

, CXF 2.2.8 , :

1) META-INF/cxf/org.apache.cxf.Logger , :

org.apache.cxf.common.logging.Slf4jLogger

Maven, src/main/resources/META-INF/cxf, src/main/webapp!

2). , CXF LoggingFeature, prettyLogging true CXF.

3) jar log4j slf4j-log4j12. Maven, :

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>${slf4j.version}</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>${log4j.version}</version>
    </dependency>

4). log4j.xml org.apache.cxf.services INFO, additivity FALSE appender:

<!-- level INFO needed to log SOAP messages -->
<logger name="org.apache.cxf.services" additivity="false">
    <level value="INFO" />
    <!-- specify a dedicated appender for the SOAP messages -->
    <appender-ref ref="WS_LOG_FILE" /> 
</logger>

, CXF log4j.

+9

All Articles