springboot+cxf+logback报文日志日志记录(已实现将不同接口写入不同日志)

0. 问题来源
https://blog.youkuaiyun.com/a116475939/article/details/88526218
继上一篇博客之后,已经可以在发布cxf接口,并且记录日志报文到日志文件中。
但是所有接口的日志都在一个文件中,这样很不合理,不便于追溯问题查找日志。
所以今天则要实现这个功能。

1. 问题思考

    @Bean(name = Bus.DEFAULT_BUS_ID)
	public SpringBus springBus() {
		SpringBus springBus = new SpringBus();
		LoggingFeature logFeature = new LoggingFeature();
		logFeature.setPrettyLogging(true);
		logFeature.initialize(springBus);
		springBus.getFeatures().add(logFeature);
		return springBus;
	}

在上个博客中,笔者使用LoggingFeature作为默认的日志记录工具。
然而,进入LoggingFeature之后,发现这个类已经弃用了。

import org.apache.cxf.common.injection.NoJSR250Annotations;
import org.apache.cxf.interceptor.AbstractLoggingInterceptor;
import org.apache.cxf.interceptor.InterceptorProvider;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;


@NoJSR250Annotations
@Deprecated
@Provider(value = Type.Feature)
 *
 * @deprecated use the logging module rt/features/logging instead
 */
public class LoggingFeature extends AbstractFeature {
    private static final int DEFAULT_LIMIT = AbstractLoggingInterceptor.DEFAULT_LIMIT;
    private static final LoggingInInterceptor IN = new LoggingInInterceptor(DEFAULT_LIMIT);

通过,这句话,了解到已经这块东西应该是废弃 并移植到另外的模块里了

use the logging module rt/features/logging instead

于是我就找到了

	    <dependency>
	      <groupId>org.apache.cxf</groupId>
	      <artifactId>cxf-rt-features-logging</artifactId>
	      <version>3.2.5</version>
	    </dependency>		

然后查找资料,配置springBus,添加日志拦截器LoggingInInterceptor/LoggingOutInterceptor

	/**
	 * @description 启用日志记录
	 * @author fg
	 * @date 2019年1月11日
	 */
	@Bean(name = Bus.DEFAULT_BUS_ID)
	public SpringBus springBus() {
		SpringBus springBus = new SpringBus();
		LoggingInInterceptor ipt = new LoggingInInterceptor();
		LoggingOutInterceptor opt = new LoggingOutInterceptor();
		ipt.setPrettyLogging(true);
		ipt.setLimit(LOG_LIMIT);
		opt.setPrettyLogging(true);
		opt.setLimit(LOG_LIMIT);
		springBus.getInInterceptors().add(ipt);
		springBus.getOutInterceptors().add(opt);
		return springBus;
	}

然而日志并未及时生效。

2. 深入分析
通过查看LoggingInInterceptor源码

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agr
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值