Reputation: 77
I have created Restful Web Service in that creating log file using log4j Instead of java.util.logging. but it didn't write for inbound and outbound messages to log file.
below to message logging configuration.
I created to META-INF/cxf/org.apache.cxf.Logger file. then i put below configuration line.
org.apache.cxf.common.logging.Log4jLogger
Then I created WEB-INF/classes/log4j.properties configuration file. below to log4j configuration
# Root logger option
log4j.rootLogger=INFO, file, stdout
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=D:\\wslog\\log.txt
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
below configuration for Enable to message logging in cxf.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://cxf.apache.org/core
http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<jaxrs:server id="base" address="/rest">
<jaxrs:features>
<cxf:logging/>
</jaxrs:features>
<jaxrs:serviceBeans>
<ref bean="MultiArgs" />
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="MultiArgs" class="com.multiArgs.MultiArgsImpl" />
</beans>
I got logging messages for
18:48:55,168 INFO ContextLoader:194 - Root WebApplicationContext: initialization started
18:48:55,200 INFO XmlWebApplicationContext:456 - Refreshing Root WebApplicationContext: startup date [Tue Nov 17 18:48:55 IST 2015]; root of context hierarchy
18:48:55,231 INFO XmlBeanDefinitionReader:315 - Loading XML bean definitions from ServletContext resource [/WEB-INF/cxf.xml]
18:48:55,293 INFO XmlBeanDefinitionReader:315 - Loading XML bean definitions from class path resource [META-INF/cxf/cxf.xml]
18:48:55,418 INFO DefaultListableBeanFactory:557 - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@8245e9: defining beans [cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,base,MultiArgs]; root of factory hierarchy
18:48:56,883 INFO ContextLoader:221 - Root WebApplicationContext: initialization completed in 1699 ms
above only i got it. but i want also inbound and outbound messages. anybody help to me...
Upvotes: 2
Views: 4483
Reputation: 943
The logging feature that you've enabled will make use of the class: org.apache.cxf.feature.LoggingFeature
To enable the printing of the payloads, as part of inbound/outbound , enable the prettyLogging attribute to true
Here's the code configuration:
<bean id="loggingFeature" class="org.apache.cxf.feature.LoggingFeature">
<property name="prettyLogging" value="true" />
</bean>
Then refer the bean:
<jaxrs:features>
<ref bean="loggingFeature"/>
</jaxrs:features>
This should log all the RESTFul requests/responses
Upvotes: 2
Reputation: 974
You need to change cxf.xml file as below.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://cxf.apache.org/core
http://cxf.apache.org/schemas/core.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<cxf:bus>
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus>
<jaxrs:server id="base" address="/rest">
<jaxrs:serviceBeans>
<ref bean="MultiArgs" />
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="MultiArgs" class="com.multiArgs.MultiArgsImpl" />
</beans>
Upvotes: 1