Log Non-fatal errors on Crashlytics
Asked Answered
T

5

48

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?

Tobias answered 29/3, 2017 at 11:37 Comment(2)
you can check my answer here https://mcmap.net/q/357352/-how-to-send-crashlytics-log. Hope it helpArthralgia
So many detailed answers with upvotes, yet none actually answer the question...Irizarry
B
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"));

Bayadere answered 26/5, 2017 at 20:58 Comment(4)
However this doesn't upload the reports until an app restart, unlike iOS' recordError.Paleethnology
@Paleethnology any solution of this? I want to log exception immediatelyCentral
@Central Not that I know of :(Paleethnology
recordError waits for the next app launch as well. Per firebase.google.com/docs/crashlytics/… "Crashlytics lets you record non-fatal exceptions and sends them to you the next time your app launches."Sweyn
D
23

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")
Disjunction answered 24/11, 2020 at 5:24 Comment(0)
I
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);
Immeasurable answered 1/2, 2019 at 9:44 Comment(2)
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.Cacuminal
If this is coming from 'io.fabric' it has been deprecated, don't use this.. Use FirebaseCrahlytics instead.Pitfall
G
3

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

Firebase.crashlytics.recordException(e)
Granados answered 31/1, 2023 at 14:10 Comment(0)
C
0

if you want to record non fatel error log in your app In my case i used it as logging all the request other then 200 from server. you can use like this as well. For this you can use just this after all the configurations

FirebaseCrashlytics.instance.log('Here is My custom Error for it ');
Considerable answered 24/1, 2024 at 12:15 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.