一 实例
package org.crazyit.cloud.log;
import org.crazyit.cloud.HelloClient;
import org.crazyit.cloud.interceptor.MyInterceptor;
import feign.Feign;
import feign.Logger;
public class LogMain {
public static void main(String[] args) {
/**
* NONE:默认值,不记录日志
* BASIC:记录请求方法、URL、响应状态代码和执行时间
* HEADERS:除BASIC记录的日志外,还会记录请求头和响应头的信息
* FULLL:在HEADERS的基础上,请求和响应的元数据,都会保存
*/
HelloClient client = Feign.builder()
.logLevel(Logger.Level.FULL)
.logger(new Logger.JavaLogger().appendToFile("logs/http.log"))
.target(HelloClient.class,
"http://localhost:8080");
String result = client.hello();
System.out.println(result);
}
}
二 启动服务类
三 测试结果
[HelloClient#hello] ---> GET http://localhost:8080/hello HTTP/1.1
[HelloClient#hello] ---> END HTTP (0-byte body)
[HelloClient#hello] <--- HTTP/1.1 200 (73ms)
[HelloClient#hello] content-length: 11
[HelloClient#hello] content-type: text/plain;charset=UTF-8
[HelloClient#hello] date: Sat, 21 Jul 2018 03:42:20 GMT
[HelloClient#hello]
[HelloClient#hello] Hello World
[HelloClient#hello] <--- END HTTP (11-byte body)