Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

android - Trouble with logging my data with crashlytics

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...