一、概念

Feign的日志非常灵活,可以为指定的Feign客户端指定日志记录策略,每个Feign客户端都会创建一个logger.

Feign的日志打印支队DEBUG级别作出响应。

我们可以为Feign客户端配置对应的Logger.Level对象,有以下值供选择。

  • NONE:不记录任何值

  • BASIC:仅记录请求方法、URL、响应状态及执行时间

  • HEADERS:记录BAISC级别的基础上,记录响应的请求和响应header

  • FULL:外加body和元数据

二、代码修改

修改movie服务

1、编写Feign配置类

import feign.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FeignLogConfiguration {
    @Bean
    Logger.Level feignLoggerLevel(){
        return Logger.Level.FULL;
    }
}

2、修改feign接口,增加配置类

@FeignClient(name = "user",configuration = FeignLogConfiguration.class)
public interface UserFeignClient {
    @RequestMapping(value = "/user/getUserInfo", method = RequestMethod.GET)
    Map findById(@RequestParam("userId") Integer userId);
}

3、修改yml文件,设置日志级别为debug

logging:
  level:
    com.my.movie.service.feignService.UserFeignClient: DEBUG

三、测试

访问  http://localhost:8020/movie/findById/feign?userId=1

观察movie控制台,打印出如下信息

springCloud入门学习(十):Feign的日志_第1张图片