?1、创建FEIGN配置文件
import feign.Client;
import feign.Logger;
import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
import org.springframework.cloud.openfeign.ribbon.CachingSpringLoadBalancerFactory;
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FeignConfiguration {
@Bean
Logger.Level feignLoggerLevel() {
//NONE,无记录(DEFAULT)
//BASIC,只记录请求方法和URL以及响应状态代码和执行时间。
//HEADERS,记录基本信息以及请求和响应标头。
//FULL,记录请求和响应的头文件,正文和元数据。
return Logger.Level.BASIC; //设置返回日志登记
}
/**
* 自定义feign.Client
* @return
*/
@Bean
public Client feignIPClient(CachingSpringLoadBalancerFactory cachingFactory,
SpringClientFactory clientFactory) {
return new LoadBalancerFeignClient(new FeignIPClient(),cachingFactory, clientFactory);
}
}
import feign.Client;
import feign.Request;
import feign.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSocketFactory;
import java.io.IOException;
public class FeignIPClient extends Client.Default {
Logger logger = LoggerFactory.getLogger("FeignIPClient");
/**
* 默认构造方法
*/
public FeignIPClient(){
this(null,null);
}
/**
* Null parameters imply platform defaults.
* @param sslContextFactory
* @param hostnameVerifier
*/
public FeignIPClient(SSLSocketFactory sslContextFactory, HostnameVerifier hostnameVerifier) {
super(sslContextFactory, hostnameVerifier);
}
@Override
public Response execute(Request request, Request.Options options) throws IOException {
//打印目标节点IP
logger.info("======请求至:---> {}",request.url());
return super.execute(request,options);
}
}
2、指定FEIGNCLIENT要读取的配置
@FeignClient(name = "xxx", configuration = FeignConfiguration.class,path = "/api/ala")
public interface ServerFeign {
@RequestMapping(value = "/xxxxx/getDate",method = RequestMethod.POST)
String getDate(@RequestBody GetAlarmRpcReq getAlarmReq);
}
3、在配置文件中开启FEIGN日志
?.yml这样配置
logging:
level:
#包名
com:
service:
ServiceFeign: debug
.properties这样
logging.level.com.service.ServiceFeign: debug
|