xml来记录CXF入站出站请求

xml来记录CXF入站出站请求

本文介绍了如何通过Spring加载log4j2.xml来记录CXF入站出站请求/响应xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在战争中有log4j.xml,我曾用它记录传入和传出的请求以及对特定日志文件的响应.

I have log4j.xml in my war which I used to log incoming and outgoing request and responses to a specific log file.

这是我的log4j.xml

This is my log4j.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true"
xmlns:log4j='http://jakarta.apache.org/log4j/'>

<appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd MMM yyyy HH:mm:ss} %5p %c{1} - %m%n" />
</layout>
</appender>

<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="append" value="true" />
<param name="file" value="Folder/ABC.log" />
<param name="MaxFileSize" value="50MB" />
<param name="MaxBackupIndex" value="50" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n" />
</layout>
</appender>
<logger name="org.apache.cxf">
<level value="INFO" />
<appender-ref ref="fileAppender" />
</logger>
<root>
<priority value="DEBUG" />
<appender-ref ref="consoleAppender" />
<appender-ref ref="fileAppender" />
</root>

</log4j:configuration>

在applicationContext.xml中添加了log4j配置

Added log4j configuration in applicationContext.xml

<!--This is for log4j configuration -->
<bean id="log4jInitialization"
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="org.springframework.util.Log4jConfigurer" />
<property name="targetMethod" value="initLogging" />
<property name="arguments">
<list>
<value>classpath:/log4j.xml</value>
</list>
</property>
</bean>

想对log4j2做类似的配置.如果有人可以共享log4j2配置,这将非常有帮助.我在Google上搜索了很多,但没有帮助.

Would like to do similar configuration for log4j2. It would be very helpful, if can someone share the log4j2 configuration. I searched a lot in google, but nothing helps.

谢谢.

推荐答案

假设您使用的是CXF 2.2.8或更高版本,则需要执行以下操作:

Assuming you are using CXF 2.2.8 or higher, you would need to do the following:

步骤1)在包含以下内容的类路径上创建文件"META-INF/cxf/org.apache.cxf.Logger": org.apache.cxf.common.logging.Slf4jLogger

step 1) Create a file 'META-INF/cxf/org.apache.cxf.Logger' on the classpath containing the following: org.apache.cxf.common.logging.Slf4jLogger

步骤2)如果要记录所有消息,请创建CXF LoggingFeature,将prettyLogging属性设置为true并将其添加到CXF总线.

step 2) If you want to log all messages, create a CXF LoggingFeature, set the prettyLogging property to true and add it to the CXF bus.

步骤3)添加Log4j2和Log4j 2 SLF4J绑定所需的jar文件.如果您使用的是maven,请包括以下依赖项:

step 3) Add the needed jar files for Log4j2 and the Log4j 2 SLF4J Binding. If you are using maven, include following dependencies:

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>${log4j2.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>${log4j2.version}</version>
</dependency>

我创建了博客文章,其中详细介绍了如何为log4j2配置CXF .

这篇关于如何通过Spring加载log4j2.xml来记录CXF入站出站请求/响应xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 19:36