我正在尝试使用 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 类路径的一部分,因此它应该在 WEB-INF/classes/META-INF/cxf/org.apache.cxf.Logger
一旦你的 WAR已妥善包装。
最后,查看您的 log4j 配置文件,您没有将 CXF 记录器级别设置为 INFO
,如下所示:
log4j.appender.org.apache.cxf.Threshold=INFO
尝试在 log4j 配置的末尾添加这一行。
关于java - 在 CXF 中使用 log4j 登录和注销拦截器消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33959966/