Tec*_*nch 3 java logging logback slf4j retrofit
我正在为REST API开发一个JAVA客户端.我正在为客户使用Retrofit.我看到我可以在改造中创建适配器时设置日志级别.所有这些日志目前都进入控制台.但是,我想将其重定向到由已在应用程序中使用的logback生成的日志.我该怎么做呢 ?
RestAdapter restAdapter = new RestAdapter.Builder()
.setLogLevel(RestAdapter.LogLevel.FULL).setEndpoint(APP_URL)
.setRequestInterceptor(new AuthRequestInterceptor())
.setErrorHandler(new RetrofitErrorHandler()).build();
Run Code Online (Sandbox Code Playgroud)
产量
---> HTTP GET http://localhost:8080/services/v1/countries
Auth-Token: ...
---> END HTTP (no body)
<--- HTTP 200 http://localhost:8080/services/v1/countries (448ms)
Transfer-Encoding: chunked
: HTTP/1.1 200 OK
Vary: Accept-Encoding
Date: Thu, 04 Jun 2015 01:36:29 GMT
Content-Type: application/json
...
<--- END HTTP (9130-byte body)
Run Code Online (Sandbox Code Playgroud)
我想要所有这些都去记录器日志.
该RestAdapter.Builder还支持传递一个登录使用setlog命令的方法. Log只是一个界面.创建自己的该接口的Logback实现,并在创建时将其传递给构建器RestAdapter.
public class LogbackLog implements Log {
public void log(String message) {
// call logback logger from here
}
}
Log logger = new LogbackLog();
RestAdapter restAdapter = new RestAdapter.Builder()
.setLog(logger)
.setLogLevel(RestAdapter.LogLevel.FULL).setEndpoint(APP_URL)
.setRequestInterceptor(new AuthRequestInterceptor())
.setErrorHandler(new RetrofitErrorHandler()).build();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
518 次 |
| 最近记录: |