如何使用 Logback 作为日志记录框架来记录通过 Web 服务模板发送的所有客户端 SOAP 消息(及其响应)?
到目前为止我看到的答案,例如: How can I make Spring WebServices log all SOAP requests?
请参阅公共(public)日志记录,我已将其排除为依赖项:
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
,或端点日志记录。
如果我理解正确,我应该提供拦截器的实现,该拦截器应该设置为 Web 服务模板属性。
有人可以向我展示代码示例如何做到这一点吗?
最佳答案
类似这样的事情:
public class LogbackInterceptor implements ClientInterceptor {
private final Logger logger = LoggerFactory.getLogger(LogbackInterceptor .class);
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
logger.debug("Sent request [" + messageContext.getRequest() + "]");
return true;
}
public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException {
logger.debug("Received response [" + messageContext.getResponse() + "] for request [" +
messageContext.getRequest() + "]");
return true;
}
.....
}
但是,不清楚为什么不添加 jcl-over-slf4j.jar
并遵循该答案中的标准 WS 登录选项?..
关于java - 如何使用 Slf4j 的 Logback 实现通过 Spring 记录 SOAP 客户端消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28044309/