66

I've been testing Firebase Crashlytics and even though the normal crash report works right I can't success trying to generate a custom as it says the documentation.

Crashlytics.log(msg); 

I also would like to know wether setting the user identifier for Crashlytics can be done for any crash (according to the doc I've understood that it's possible) with

void Crashlytics.setUserIdentifier(String identifier); 

and how it would have to be done, because it does neither work to me, I can't see anything on the Firebase crashlytics console.

Thanks in advance!

Arya
  • 1,729
  • 3
  • 17
  • 35
strok_777
  • 1,132
  • 1
  • 9
  • 27
  • 5
    do you reopen your app? because firebase message sent when you reopen your app!!! – Amir133 Dec 01 '18 at 15:43
  • Crashlytics isn't made for develop logging, it is made to cluster hundreds/thousands of logs from different users at runtime, this may cause that the dashboard doesn't show the logs in the exactly time they are produced. If you want to use Crashlytics to follow the code workflow and debug during development, you will need to use the trick in this answer. https://stackoverflow.com/a/69340289/5679560 – Rafael Lima Sep 27 '21 at 01:43

5 Answers5

64

For a better understanding, when you collect data with

FirebaseCrashlytics.getInstance().log("Test w(text)")
FirebaseCrashlytics.getInstance().log("Test e(text)")

you will get NO new non-fatal crash report in Firebase crashlytics. But follow up by a

FirebaseCrashlytics.getInstance().recordException(RunTimeException("Test e(throwable)"))

it will send this error : enter image description here

with this additional log entries within this error

enter image description here

hannes ach
  • 16,247
  • 7
  • 61
  • 84
24

The logging mechanism of Crashlytics isn't built for normal logging.

The logs that you put will show in crash reports, not as stand alone logs. Same goes for the user identifier information.

Try forcing a crash, you should see the logs captured before the crash in the crash report. If you want normal logging, you should look into Firebase analytics, it'll help you keep track of regular events and other analytics data.

Kushan
  • 5,855
  • 3
  • 31
  • 45
  • Ok, I've seen that setUserIdentifier does add the info on the crash I just provoked. But isn't there any option to add this globally, for any crash occurred? Regarding the log it think there must be a way to generate custom logs, as it can be done with FirebaseCrash.report. Anyway if the purpose of log was to attach it on the crash, in this case it doesn't appear on the console, as it does with the user identifier. – strok_777 Feb 06 '18 at 09:46
  • Unfortunately not – Kushan Feb 06 '18 at 09:51
  • 1
    But can I use something from firebase to simply log some basic string? When I write: Log.d("Potatoes") or Timber.d("More Potatoes") Can I see some "potatoes" ANYWHERE in my Firebase Console? I only found a workarround to log an Exception which then is sent to the Firebase with my custom message, but it's not really the optimal way I guess, more of a hack. – SKREFI Mar 23 '21 at 12:34
12

This worked for me.

Crashlytics.log(message);
Crashlytics.logException(exception);

Edit: I had missed this explanation.

strok_777
  • 1,132
  • 1
  • 9
  • 27
  • 3
    That what I was missing: `Crashlytics.log()` alone does nothing, it has to be used with `Crashlytics.logException()`. Thanks! – matteoh Feb 09 '20 at 19:13
  • 1
    "Crashlytics" doesn't exist, this is probably code from the old API. – Andrew Koster Jul 29 '20 at 16:55
  • ["Crashlytics only stores the most recent eight recorded exceptions. If your app throws more than eight exceptions, older exceptions are lost."](https://firebase.google.com/docs/crashlytics/customize-crash-reports?platform=android#log-excepts) – heronsanches Sep 05 '20 at 01:54
  • `Crashlytics.crashlytics().log("TEST")` – adnako Nov 02 '20 at 14:31
9

Just for updating the answer for log Kotlin with Firebase it is:

FirebaseCrashlytics.getInstance().log(error.toString())

And for Exception

FirebaseCrashlytics.getInstance().recordException(e)

See documentation: https://firebase.google.com/docs/crashlytics/get-started?platform=Android

Júlio Reis
  • 306
  • 5
  • 7
  • 1
    "FirebaseCrashlytics" doesn't exist. – Andrew Koster Jul 29 '20 at 16:55
  • @AndrewKoster could you tell me in more details ? My Android app it is working fine with "FirebaseCrashlytics" Did you add it to your app graddle ? – Júlio Reis Jul 29 '20 at 23:59
  • The problem is that I was following https://firebase.google.com/docs/android/setup which does NOT include any of the dependencies required to use Crashlytics itself. I finally found https://firebase.google.com/docs/crashlytics/get-started?platform=android which is complete and accurate. I'll switch my vote if you add that last URL to the answer. – Andrew Koster Jul 30 '20 at 00:20
  • @AndrewKoster, sure. – Júlio Reis Jul 30 '20 at 15:16
  • This code `FirebaseCrashlytics.getInstance().recordException(e)` working fine to get any exeption regarding code. Thank you so much – M DEV Jul 10 '22 at 13:43
2

I also had big problems getting anything to show up but I figured it out. In my case the problem was me versus the user interface at the crashlytics site.

You have to disable the filter saying Event Type="Crashes" to be able to see those other events.

Disable the filter here

Erik Melkersson
  • 899
  • 8
  • 19