HomeDocumentationAPI Reference
Getting StartedAPI ReferenceBug ReportingCrash ReportingAPMHelp Center
These docs are for v8.1. Click to read the latest docs for v12.0.0.

Report Logs

This section covers how Instabug automatically attaches console logs, verbose logs, and all steps made by your users before a bug report is sent for Android apps.

🚧

Privacy Policy

It is highly recommended to mention in your privacy policy that you may be collecting logging data in order to assist troubleshooting bugs.

A variety of log types are sent with each crash or bug report. They appear within each report in your Instabug dashboard, as shown below. Log collection stops when Instabug is shown.

We support the following types of logs:

2169

An example of the expanded logs view from your dashboard.

User Steps

Instabug can help you reproduce issues by tracking each step a user has taken until a report is sent. Note that the maximum number of user steps sent with each report is 100.

To allow Instabug to record user steps, you need to call the following method from your Activity.

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
	InstabugTrackingDelegate.notifyActivityGotTouchEvent(ev, this);
	return super.dispatchTouchEvent(ev);
}

User Steps are formatted as follows: Event in text/viewID of type class in parentView.

  • The type of events captured are tap, double tap, long press, swipe, scroll and pinch.
  • text/viewID refers to the text or the ID of the object that contains the event.
  • Class refers to the class of the object that contains the event.
  • ParentView refers to the view that contained the event.
2160

An example of the expanded logs view filtered by User Steps.

Tracking Fragments

If you tend to use fragments in your application, you will need to track them manually. In order to do so, add the following method to the Activity holding the fragment.

@Override public boolean dispatchTouchEvent(MotionEvent ev){  
           InstabugTrackingDelegate.notifyActivityGotTouchEvent(ev, this);  
           return super.dispatchTouchEvent(ev); 
}

Then, create a base fragment class. You'll need to call InstabugTrackingDelegate's fragment life-cycle methods from your fragment's life-cycle callbacks. These methods are as follows:

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
           super.onViewCreated(view, savedInstanceState);
           InstabugTrackingDelegate.notifyFragmentViewCreated(view, this, getActivity());
}

@Override
public void onStart() {
           InstabugTrackingDelegate.notifyFragmentStarted(this, getActivity());
           super.onStart();
}

@Override
public void onResume() {
           InstabugTrackingDelegate.notifyFragmentResumed(this, getActivity());
           super.onResume();
}

@Override
public void onPause() {
           InstabugTrackingDelegate.notifyFragmentPaused(this, getActivity());
           super.onPause();
}

@Override
public void onStop() {
           InstabugTrackingDelegate.notifyFragmentStopped(this, getActivity());
           super.onStop();
}

📘

Why in a base fragment?

A base fragment can use this code, which you can then inherit in other fragments you already have without the need to write redundant code.

Repro Steps

Repro Steps show you all of the interactions a user makes with your app up until a bug or crash is reported, grouped by app view. For each view that a user visits, all of the steps that they commit within those views are captured and displayed as a log along with a screenshot or GIF of each view in your dashboard. The limit for each report is 100 log statements and 20 screenshots.

To enable Instabug to record user steps, you need to call the following method from your Activity.

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
	InstabugTrackingDelegate.notifyActivityGotTouchEvent(ev, this);
	return super.dispatchTouchEvent(ev);
}

This feature is available starting from the Silver Plan. You can control it through the setReproStepsState Instabug builder method.

//Method 1
new Instabug.Builder(this, “APP_TOKEN”)
	.setInvocationEvents(InstabugInvocationEvent.SHAKE)
  .setReproStepsState(State.ENABLED)
	.build(); 

//Method 2
Instabug.setReproStepsState(State.ENABLED);

Here are the possible arguments.

State.ENABLED;
State.DISABLED;

Network Logs

Instabug automatically logs all network requests performed by your app. Requests details, along with their responses, are sent with each report. Instabug will also show you an alert at the top of the bug report in your dashboard when network requests have timed-out or taken too long to complete. Note that the maximum number of network logs sent with each report is 1,000.

2160

An example of network request logs in the Instabug dashboard.

Logging HttpUrlConnection requests

To log network requests, use InstabugNetworkLog then use the following method at the HttpUrlConnection, requestBody and responseBody.

InstabugNetworkLog networkLog = new InstabugNetworkLog();
 networkLog.Log(urlConnection, requestBody, responseBody);

For a more detailed example, see the following network request.

@Override
protected String doInBackground(Void... params) {
	
  HttpURLConnection urlConnection = null;
  BufferedReader reader = null;
  String moviesJsonStr = null;
	
  try {
    URL url = new URL("<YOUR_URL>");
    urlConnection = (HttpURLConnection) url.openConnection();
    urlConnection.setDoOutput(true);
    urlConnection.setRequestMethod("POST");        
    urlConnection.setUseCaches(false);           
    urlConnection.setConnectTimeout(10000);            
    urlConnection.setReadTimeout(10000);           
    urlConnection.setRequestProperty("Content-Type", "application/json");         
    urlConnection.connect();
    
    JSONObject jsonParam = new JSONObject();         
    try {        
      jsonParam.put("PARAM_1", "one");           
      jsonParam.put("PARAM_2", "two");       
    } catch (JSONException e) {            
      e.printStackTrace();        
    }
		
    OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream());
    out.write(jsonParam.toString());   
    out.close();

    InputStream inputStream = urlConnection.getInputStream();
    StringBuffer buffer = new StringBuffer();
    if (inputStream == null) {
    	return null;
    }
                
    reader = new BufferedReader(new InputStreamReader(inputStream));              
    String line;        
    while ((line = reader.readLine()) != null) {
      buffer.append(line + "\n");   
    }
		
    if (buffer.length() == 0) {                 
      // Stream was empty.  No point in parsing.             
      return null;      
    }
    moviesJsonStr = buffer.toString();

    //logging network request to instabug
    InstabugNetworkLog networkLog = new InstabugNetworkLog();
    networkLog.Log(urlConnection, jsonParam.toString(), moviesJsonStr);

    return moviesJsonStr;
}

Logging Okhttp requests

First, you will need to compile Instabug with a network interceptor.

compile 'com.instabug.library:instabug-with-okhttp-interceptor:8+'

To log Oktthp requests, use the InstabugOkhttpInterceptor as shown in the following example.

InstabugOkhttpInterceptor instabugOkhttpInterceptor = new InstabugOkhttpInterceptor();

OkHttpClient client = new OkHttpClient.Builder()
	.addInterceptor(interceptor)
	.addInterceptor(instabugOkhttpInterceptor)
	.build();

Instabug Logs

You can log messages throughout your application's lifecycle to be sent with each report. InstabugLog works just like the regular Log class you use to show colorful logs in your logcat. Note that the maximum number of Instabug logs sent with each report is 1,000.

InstabugLog.d("Message to log");
InstabugLog.v("Message to log");
InstabugLog.i("Message to log");
InstabugLog.e("Message to log");
InstabugLog.w("Message to log");
InstabugLog.wtf("Message to log");

Console Logs

Instabug captures all console logs and displays them on your dashboard with each report. Note that the maximum number of console logs sent with each report is 1,000 statements with a limit of 5,000 characters for each statement.

User Events

You can log custom user events throughout your application and they will automatically be included with each report. Note that the maximum number of user events sent with each report is 1,000.

Instabug.logUserEvent("Logged in");

What’s Next

Logs go hand-in-hand with both bug and crash reporting, so why not give those a look? The Session Profiler feature also give you more comprehensive details alongside logs.