1

From time to time I'm getting a NPE in an app I have published on Play Store and I'd like to log some extra info so I can better understand what's wrong.

Therefore I followed this guide from Fabric for enhanced reports hoping that I will see the value from a variable I log in the stack trace.

This is the code I used:

id = table.getId();    // <------ line that throws NPE
Crashlytics.log("userIsOnline: " + isOnline);   // <----- variable I want to know it's value

Today I got the stack trace from two crashes but no variable was logged. Isn't this how I should log it or is there something else I haven't understand ?

mt0s
  • 5,781
  • 10
  • 42
  • 53

3 Answers3

1

You can use FirebaseAnalytics for log event during a crash. You can use it to log events with the logEvent() method.

The following example show how to log a suggested SELECT_CONTENT Event:

val bundle = Bundle()
bundle.putString(FirebaseAnalytics.Param.ITEM_ID, id)
bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, name)
bundle.putString(FirebaseAnalytics.Param.CONTENT_TYPE, "image")
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, 
bundle)

You can log your own custom events as shown in this example:

val params = Bundle()
params.putString("image_name", name)
params.putString("full_text", text)
firebaseAnalytics.logEvent("share_image", params)

Hope the above example will help you.

Sanjay Bhalani
  • 2,424
  • 18
  • 44
1

As official docs says

Crashlytics.log() will only write to the Crashlytics crash report.

Use it above id = table.getId(); and check data in Non-Fatals tab in Fabric.

Stanislav Bondar
  • 6,056
  • 2
  • 34
  • 46
0
Log non-fatal exceptions
In addition to automatically reporting your app’s crashes, Crashlytics lets you log non-fatal exceptions.

On Android, that means you can log caught exceptions in your app’s catch blocks:

try {
    methodThatThrows();
} catch (Exception e) {
    Crashlytics.logException(e);
    // handle your exception here
}
Anupam
  • 2,845
  • 2
  • 16
  • 30