I'm using the Ion async HTTP library for Android and I'd like to do some custom logging. What would be ideal was to hook onto every reqest start and end in order to get the total request time and some other meta data like HTTP response code and URL. Anyone know of any way to do this?
I'm experimenting with setAsyncHttpRequestFactory
, but that only seems to allow be too hook onto request begin, not end.
Ion.Config ionConf = Ion.getDefault(appContext).configure();
final AsyncHttpRequestFactory reqFac = ionConf.getAsyncHttpRequestFactory();
ionConf.setAsyncHttpRequestFactory((uri, method, headers) -> {
// Do custom logging stuff here
AsyncHttpRequest req = reqFac.createAsyncHttpRequest(uri, method, headers);
return req;
});
Implement and add a AsyncHttpClientMiddleware (inherit from SimpleMiddleware) and inject it into AsyncHttpClient's pipeline. Override onRequest and onResponseCompleted to get events for the start and end of request.
Or, if you just enable Ion logging globally, you can see request time, and all sorts of metadata in adb logcat.