I'm trying to get logs with some service data with Crashlytics in my android application. But I don't see my logs in dashboard. I used this:
String myLog = getServiceData(); //myLog is not null and non-empty CrashLytics.log(myLog);
and this:
String myLog = getServiceData(); //myLog is not null and non-empty CrashLytics.log(Log.Error, getString(R.string.app_name), myLog);
I tried to generate exception in my application and handle it, but have no results:
try { int a = 0; a = 1/a; } catch (Exception e) { CrashLytics.log(myLog); }
Also I read on Crashlytics log not sent I need to initialize crashlytics before log data. I put Crashlytics.start(this) in onStart() event of my Activity but didn't see my logs in dashboard again. At last I tried to put Crashlitycs.start(this) directly before logging my data, but still have no logs in dashboard.
Plase, tell me what I do wrong and how to get my custom logs in Crashlytics dashboard?
Crashlytics associates the logs with your crash data and displays them in the Crashlytics page of the Firebase console, under the Logs tab.
Crashlytics creates a exception handler that intercepts the exceptions that weren't caught and does something with them but it also sends the exception to the previous exception handler, that's why the app stills crashes.
I had a similar situation. With some experimenting, I was able to deduce the rules to Crashlytics' behavior.
I'm sharing my learnings here so (hopefully) others don't have to go through the arduous and time-consuming process that I did to figure it out.
Crashlytics will only upload a crash report "to the dashboard" immediately if a fatal exception occurs. In other words, when your app crashes. And nothing shows in the dashboard unless and until a crash report is uploaded.
If you log a non-fatal exception, using CrashLytics.logException(e)
, a crash report will not be uploaded till the next time your app is restarted. So you will not see the exception in the Crashlytics dashboard till an app restart.
You can tell when an upload occurs because you'll see this sort of message in LogCat:
07-17 19:30:41.477 18815-18906/com.foo.bar I/Crashlytics﹕ Crashlytics report upload complete: 55A9BA0C01D7-0001-462D-B8B4C49333333.cls
A Crashlytics log message must be associated with a fatal or non-fatal exception to show up in the dashboard.
Furthermore, log messages that aren't associated with an exception do not survive app restart.
So, if you do something like log a few messages, then restart the app, then the app throws an exception, or it logs a non-fatal exception using Crashlytics.logException()
, the log messages will be lost. They will not show up in the dashboard.
If you want to log some messages without a fatal exception, use one or more Crashlytics.log()
statements followed by Crashlytics.logException()
.
To verify that it works, have the code run, then restart the app. In the dashboard, you should see the logs associated with the issue created for the non-fatal exception. In the wild, you'll just have to trust your users restart the app with some regularity.
On the Fabric/Crashlytics dashboard, you'll need to select All Events
or (if you want to see just your logging calls) Non-Fatals
.
according to Crashlytics knowledgebase:
Logged messages are associated with your crash data and are visible in the Crashlytics dashboard if you look at the specific crash itself.
And from my experience this seems true. However I am unsure as to what determines which logging is associated with a crash report. Perhaps a time window (time around crash) or a limited number of logs (before the crash) is associated with the crash report?
However Crashlytics knowledgebase does say that exceptions can be logged:
All logged exceptions will appear as "non-fatal" issues in the Crashlytics dashboard.
So if you changed your try/catch to:
try { int a = 0; a = 1/a; } catch (Exception e) { CrashLytics.logException(e); }
then it should show up in the Crashlytics dashboard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With