注:这里的 feignClient相关配置都是指 spring cloud中的 feign客户端,与独立的 feign会略有不同。
默认情况下feign是没有日志打印出来的,需要增加相关配置:
1、创建Feign的配置文件,并在其中设置日志等级
/**
* Feign 客户端配置
*
* @author xushiling
* @date 2018/8/13
*/
@Configuration
public class FeignConfiguration {
@Bean
Logger.Level feignLoggerLevel() {
//这里记录所有,根据实际情况选择合适的日志level
return Logger.Level.FULL;
}
}
2、在客户端接口指定此配置(根据实际情况配置,这里仅作演示)
/**
* 用户服务
*
* @author :xushiling
* @date :2018/4/2
*/
@FeignClient(value = "haoait-auth", configuration = FeignConfiguration.class, fallback = UserServiceClientHystrix.class)
public interface UserServiceClient extends UserService {
}
3、配置文件开启日志记录
application.properties设置:
logging.level.com.haoait.client.UserServiceClient:debug
如果是yml配置文件则做如下配置:
logging:
level:
com.haoait.client.UserServiceClient:debug
日志输出如下:
2018-08-13 17:32:45.247 DEBUG [haoait-demo-consumer,475fc921d2eac9ae,475fc921d2eac9ae,false] 1016 --- [x-haoait-auth-3] com.haoait.client.UserServiceClient : [UserServiceClient#findAllUser] ---> POST http://haoait-auth/getUser HTTP/1.1
2018-08-13 17:32:45.247 DEBUG [haoait-demo-consumer,475fc921d2eac9ae,475fc921d2eac9ae,false] 1016 --- [x-haoait-auth-3] com.haoait.client.UserServiceClient : [UserServiceClient#findAllUser] ---> END HTTP (0-byte body)
2018-08-13 17:32:45.284 DEBUG [haoait-demo-consumer,475fc921d2eac9ae,475fc921d2eac9ae,false] 1016 --- [x-haoait-auth-3] com.haoait.client.UserServiceClient : [UserServiceClient#findAllUser] <--- HTTP/1.1 200 (36ms)
2018-08-13 17:32:45.284 DEBUG [haoait-demo-consumer,475fc921d2eac9ae,475fc921d2eac9ae,false] 1016 --- [x-haoait-auth-3] com.haoait.client.UserServiceClient : [UserServiceClient#findAllUser] content-type: application/json;charset=UTF-8
2018-08-13 17:32:45.284 DEBUG [haoait-demo-consumer,475fc921d2eac9ae,475fc921d2eac9ae,false] 1016 --- [x-haoait-auth-3] com.haoait.client.UserServiceClient : [UserServiceClient#findAllUser] date: Mon, 13 Aug 2018 09:32:45 GMT
2018-08-13 17:32:45.284 DEBUG [haoait-demo-consumer,475fc921d2eac9ae,475fc921d2eac9ae,false] 1016 --- [x-haoait-auth-3] com.haoait.client.UserServiceClient : [UserServiceClient#findAllUser] transfer-encoding: chunked
2018-08-13 17:32:45.284 DEBUG [haoait-demo-consumer,475fc921d2eac9ae,475fc921d2eac9ae,false] 1016 --- [x-haoait-auth-3] com.haoait.client.UserServiceClient : [UserServiceClient#findAllUser] x-application-context: haoait-auth:3030
2018-08-13 17:32:45.284 DEBUG [haoait-demo-consumer,475fc921d2eac9ae,475fc921d2eac9ae,false] 1016 --- [x-haoait-auth-3] com.haoait.client.UserServiceClient : [UserServiceClient#findAllUser]
2018-08-13 17:32:45.285 DEBUG [haoait-demo-consumer,475fc921d2eac9ae,475fc921d2eac9ae,false] 1016 --- [x-haoait-auth-3] com.haoait.client.UserServiceClient : [UserServiceClient#findAllUser] {"code":"200","msg":"成功","total":10000,"rows":[{"id":1,"createTime":1505265663000,"code":"admin","name":"超级管理员1","password":"123456","updateTime":1505265663000},{"id":171,"createTime":1517109680914,"code":"lixx","name":"李小小","password":null,"updateTime":null},{"id":172,"createTime":1517109758814,"code":"lixx2","name":"李xx2","password":"123456","updateTime":null},{"id":173,"createTime":1517121895407,"code":"test1","name":"test1","password":"123","updateTime":null},{"id":174,"createTime":1518752201438,"code":"hank250","name":"李小熊","password":null,"updateTime":null},{"id":175,"createTime":1520756361675,"code":"test123","name":"test12344","password":null,"updateTime":null}]}
2018-08-13 17:32:45.285 DEBUG [haoait-demo-consumer,475fc921d2eac9ae,475fc921d2eac9ae,false] 1016 --- [x-haoait-auth-3] com.haoait.client.UserServiceClient : [UserServiceClient#findAllUser] <--- END HTTP (707-byte body)