Log Non-fatal errors on Crashlytics

25,670

Solution 1

What I do in order to report a non-fatal issue is to log an exception using the following code (remember you can throw any subclass of Exception):

Crashlytics.logException(new Exception("My custom error message"));

Solution 2

You can also use Crashlytics below features to provide more information.

Logging Non-Fatal Events:

try {
  myMethodThatThrows();
} catch (Exception e) {
  Crashlytics.logException(e);
  // handle your exception here!
}

Add some more messages:

Crashlytics.log(int priority, String tag, String msg);
Crashlytics.log("Higgs-Boson detected! Bailing out...");

Also you can provide some user information:

void Crashlytics.setUserIdentifier(String identifier);
void Crashlytics.setUserName(String name);
void Crashlytics.setUserEmail(String email);

Solution 3

For those who have migrated from Fabric-Crashlytics SDK to Firebase-Crashlytics SDK, the new way of logging non-critical exceptions or exceptions which have been caught in a try-catch block is this -

FirebaseCrashlytics.getInstance().recordException(e)

To add additional data fields to the crash report you can key-value pairs before logging the exception like this

val crashlytics = FirebaseCrashlytics.getInstance()
crashlytics.setCustomKey("position", 1)
crashlytics.setCustomKey("marker_mode", "hidden")
crashlytics.setCustomKey("direction_shown", true)

To add some log messages,

FirebaseCrashlytics.getInstance().log("Reached breakpoint 2")
Share:
25,670
Eselfar
Author by

Eselfar

"Many of the truths we cling to depend greatly on our own point of view"

Updated on November 24, 2020

Comments

  • Eselfar
    Eselfar over 3 years

    On iOS it's possible to use recordError(error) to log non-fatal errors on Crashlytics but apparently this feature is not available for Android.

    The only alternative I found is to use logException(e). I manage errors on my app and I want to log when specifics errors codes are returned. So, on Crashlytics I'd like the non-fatal errors to be referenced by the errorCode. But using the logException(e) method, errors are referenced by the method where logException(e) has been called.

    How can I do that?