44

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?

Eselfar
  • 3,759
  • 3
  • 23
  • 43

4 Answers4

49

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"));

22

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")
vepzfe
  • 4,217
  • 5
  • 26
  • 46
18

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);
0xAliHn
  • 18,390
  • 23
  • 91
  • 111
  • 9
    Crashlytics.log("msg") is good for only as an additional complement for a possible future exception, otherwise, a dev will not find it on the Crashltyics dashboard. – ultraon Feb 04 '19 at 22:38
  • If this is coming from 'io.fabric' it has been deprecated, don't use this.. Use FirebaseCrahlytics instead. – VoidMain Mar 23 '22 at 14:18
2

As per the latest version of Crashlytics library 2.9.2 .. You can log non-fatal exception through this code

Firebase.crashlytics.recordException(e)
Muhamed El-Banna
  • 593
  • 7
  • 21