How to log Apache CXF Soap request and response using Log4j

This article shows how to log inbound and outbound message using CXF interceptors.

1. Configure In and Out Logging interceptors

CXF provides interceptors for Inbound and Outbound message logging. Below the configuration to activate them.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
	<import resource="classpath:META-INF/cxf/cxf.xml" />

	<!-- Loggers for SOAP calls -->
	<bean id="abstractLoggingInterceptor" class="org.apache.cxf.interceptor.AbstractLoggingInterceptor" abstract="true" />
	<bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor" parent="abstractLoggingInterceptor" />
	<bean id="loggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor" parent="abstractLoggingInterceptor" />

			<ref bean="loggingInInterceptor" />
			<ref bean="loggingOutInterceptor" />
			<ref bean="loggingOutInterceptor" />
			<ref bean="loggingInInterceptor" />

Using Log4j Instead of java.util.logging

CXF by default uses java.util.logging. If you want you can log using Log4J. Under src/main/resources/META-INF/cxf/ create a file named org.apache.cxf.Logger with the following contents:


You may need to add a category org.apache.cxf to your Log4J configuration like below:

<category name="org.apache.cxf" additivity="false">
    <priority value="INFO" />
    <appender-ref ref="LOG" />

If you want to learn more retro games news, read our magazine and subscribe to our newsletter.