![](/img/trans.png)
[英]logging full request and response using Apache cxf interceptor and log4j in spring
[英]Logging In and out Interceptor messages with log4j in CXF
我正在嘗試使用log4j將我的其余web服務的LoggingInInterceptor和LoggingOutInterceptor消息從控制台重定向到文件,如下所示,
cxf.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:cxf="http://cxf.apache.org/core"
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">
<jaxrs:server id="base" address="/Restful">
<jaxrs:serviceBeans>
<ref bean="Service" />
</jaxrs:serviceBeans>
<jaxrs:features>
<cxf:logging />
</jaxrs:features>
</jaxrs:server>
<bean id="Service" class="com.xxx.yyy.services.ServiceImpl" />
</beans>
org.apache.cxf.Logger文件
org.apache.cxf.common.logging.Log4jLogger
log4j.properties
# Root logger option
log4j.rootLogger=INFO, file, stdout
## more informations
# http://cxf.apache.org/docs/debugging-and-logging.html
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=D:\\ServiceLog.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
附加細節,
CXF 3.1.4和Java 7
在這里,我在控制台中接收這兩個消息,但它沒有在文件中寫入。
如果有人能在這里幫助我,我們將不勝感激。
謝謝,
確保在org.apache.cxf.Logger
文件中輸入一行文本
org.apache.cxf.common.logging.Log4jLogger
另外,確保它是WAR類路徑的一部分,因此一旦你的WAR正確打包,它應該在WEB-INF/classes/META-INF/cxf/org.apache.cxf.Logger
下結束。
最后,查看log4j配置文件,您錯過了將INFF記錄器級別設置為INFO
,如下所示:
log4j.appender.org.apache.cxf.Threshold=INFO
嘗試在log4j配置的末尾添加此行。
正如您可以閱讀Apache CXF - Debbuging和Logging CXF使用Java SE Logging,但您可以更改日志記錄實現:
如上所述,默認情況下,CXF使用
java.util.logging
包(“Java SE Logging”)。 但是可以將CXF切換為使用Log4J。 這是通過使用配置文件實現的。 引導CXF日志記錄有兩個選項,每個選項列在下面:
將以下系統屬性添加到初始化CXF的類路徑中:
-Dorg.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger
將文件
META-INF/cxf/org.apache.cxf.Logger
到類路徑中,並確保它包含以下內容:
org.apache.cxf.common.logging.Log4jLogger
您必須將META-INF/cxf/org.apache.cxf.Logger
文件的內容從org.apache.cxf.Logger
更改為org.apache.cxf.common.logging.Log4jLogger
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.