0

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;
    });
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Nilzor
  • 18,082
  • 22
  • 100
  • 167

1 Answers1

1

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.

koush
  • 2,972
  • 28
  • 31
  • I want to log the HTTP response body to logcat. I can't find what method to call or hook onto to get that in `onResponsecompleted` or `onRequest`, nor do I see an option to get HTTP body logging from the global logging settings (I have it at VERBOSE). Could you please provide a code example on how to get the body in any method override of SimpleMiddleWare? – Nilzor Mar 07 '16 at 12:46