Skip to main content

Logging

Beta release

The Sauce Mobile Beta SDK can log your app's network requests and handled exceptions to the session timeline, giving you an effortless way to monitor your app's network access and non-fatal errors. For the iOS-specific network setup, see Log Network.

example issues
TestFairy.addNetworkEvent(URI uri, String method, int code, long startTimeMillis, long endTimeMillis, long requestSize, long responseSize, String errorMessage);
ExampleIf you are using OkHttp or Retrofit all you need to do is add CustomHttpInterceptor to your client:
// Be sure to import the SDK
import com.testfairy.TestFairy;

public class CustomHttpInterceptor implements Interceptor {
@Override
public Response intercept(@NonNull Chain chain) throws IOException {

Request request = chain.request();
long startTimeMillis = System.currentTimeMillis();
Long requestSize = request.body() != null ? request.body().contentLength() : 0;
Response response;
try {
response = chain.proceed(request);
} catch (IOException e) {
long endTimeMillis = System.currentTimeMillis();
TestFairy.addNetworkEvent(request.url().uri(), request.method(), -1, startTimeMillis, endTimeMillis, requestSize, -1, e.getMessage());
throw e;
}

long endTimeMillis = System.currentTimeMillis();
long responseSize = response.body() != null ? response.body().contentLength() : 0;
TestFairy.addNetworkEvent(request.url().uri(), request.method(), response.code(), startTimeMillis, endTimeMillis, requestSize, responseSize, null);
return response;
}
}

OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new CustomHttpInterceptor())
.build();

Exception Logging​

Sauce Labs Mobile App Distribution allows developers to log up to five exceptions or errors for a session.

note

It does not mark the session as crashed. It only logs the exception or error to the session.

TestFairy.logThrowable(<throwable exception>);
Example
// Be sure to import the SDK
import com.testfairy.TestFairy;

TestFairy.logThrowable(new Throwable("Some Message"));