Logging using Crashlytics

2019-04-06 02:33发布

I am using multiple Crashlytics.log() commands, for example:

Crashlytics.log("This is message 1");
Crashlytics.log("This is message 2"); 

But when there is a crash in the dashboard I can only see "This is message 1" but not "This is message 2". Does Crashlytics log only show the first log not any subsequent log after that or am I doing anything wrong? How can I use multiple Crashlytics.log() commands.

5条回答
淡お忘
2楼-- · 2019-04-06 02:47

It seems that Crashlytics is writing the log messages asynchronously. So you will always have a race condition when using Crashlytics.log().

Depending on what you are doing a short (and ugly) sleep before crashing may solve this issue:

Crashlytics.log("1");
Crashlytics.log("2");
try {
    Thread.sleep(1000);
} catch (InterruptedException e) {
    // NOP: Ignored!
}
throw new RuntimeException("Failed directly after logging.");

Or you can use custom keys instead:

Crashlytics.setString("SOME_IMPORTANT_VALUE", "1");
查看更多
Animai°情兽
3楼-- · 2019-04-06 02:53

I am using the Crashlytics log system and I can see more that one log. In fact I can see all the logs that I've added to the app before the crash point.

My guess is that your app has a crash before your "message 2" log line.

查看更多
The star\"
4楼-- · 2019-04-06 03:02

acorrding to this answer:

your logs shown when you restart your application.

查看更多
别忘想泡老子
5楼-- · 2019-04-06 03:04

I'd like to add a note to other passersby that the extra logs are only viewable on a per session basis. In a given issue, click the View All Sessions button and you'll see additional info for keys and logs. All logs held by fabric are shown here, so you can log numerous times before the exception. This took a surprisingly long time for me to realize.

As others have noticed and as documented, Crashlytics may not send the log reports until a throwable is logged via logException. Keep that in mind if the logs aren't appearing on that screen.

查看更多
Luminary・发光体
6楼-- · 2019-04-06 03:08

The log message will be saved with the exception. So the Crashlytics.log("1"); wont do anything without an exception.

You should fire like that:

Crashlytics.log(Log.ERROR, "YourTAG", "YourMessage");
Crashlytics.logException(new Throwable("YourERROR"));
查看更多
登录 后发表回答