stephanenicolas / robospice

Repo of the Open Source Android library : RoboSpice. RoboSpice is a modular android library that makes writing asynchronous long running tasks easy. It is specialized in network requests, supports caching and offers REST requests out-of-the box using extension modules.
Apache License 2.0
2.95k stars 545 forks source link

How to log api response time at common place? #472

Closed sunnymopada closed 6 years ago

sunnymopada commented 6 years ago

I would like to log time taking for each API called using robospice retrofit. And I would like configure this at one place. @stephanenicolas Any ideas?

sunnymopada commented 6 years ago

I have done it using call backs. It would be great if I get request payload as well in the RequesInformation object. Thank you!

builder.setErrorHandler(new ErrorHandler() {
    @Override
    public Throwable handleError(RetrofitError cause) {
        Log.d("TAG", cause.getUrl() + ":" + cause.getMessage());
        return cause;
    }
});
builder.setProfiler(new Profiler() {
    @Override
    public Object beforeCall() {
        return null;
    }

    @Override
    public void afterCall(RequestInformation requestInfo, long elapsedTime, int statusCode, Object beforeCallData) {
        Log.d("TAG",new Gson().toJson(requestInfo)+" : "+elapsedTime);
    }
});