22

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.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user3424346
  • 221
  • 1
  • 2
  • 4
  • 1
    Check Julian's complete answer here: [http://stackoverflow.com/questions/24336444/trouble-with-logging-my-data-with-crashlytics](http://stackoverflow.com/questions/24336444/trouble-with-logging-my-data-with-crashlytics) – Fatima Sep 17 '16 at 13:31

5 Answers5

35

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"));
xnagyg
  • 4,784
  • 2
  • 32
  • 24
  • 1
    My understanding goes the same. You can only add one single log per exception. I see it like a special "big" key you can put bigger strings in. – John May 10 '16 at 11:03
  • The problem with this approach is that all of these exceptions will be filed under the same exception in the Crashlytics control panel. Even though the stacktrace may vary, it seems the critical metric here is the point at which the exception is created, which in this case, is always the same. – Mark Aug 26 '22 at 09:56
3

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.

Allan W
  • 2,791
  • 4
  • 23
  • 41
2

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.

PedroDuran
  • 392
  • 2
  • 8
2

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");
Sven
  • 559
  • 5
  • 6
  • 2
    Waiting before each line of code that might fail is not much of a solution. I've filed an error report with Crashlytics: there's no reason even their async logging can't flush their buffers when the crash handler is invoked (I have the same issue). – Pierre-Luc Paour Dec 09 '14 at 08:02
  • @Pierre-LucPaour: Any response to the issue? I seem to be getting something along the same lines. – Dennis L Apr 25 '15 at 00:18
  • Crashlytics are aware of the issue, but they have not yet addressed it, and it unfortunately doesn't seem to be very high on their list of priorities. They are very responsive if you contact them directly, and it may help raise the priority. – Pierre-Luc Paour Apr 26 '15 at 06:14
  • @Pierre-LucPaour Is your error report private ? Could you share the link otherwise ? – desseim May 29 '15 at 10:58
  • It was a private email to the community manager support@crashlytics.com – Pierre-Luc Paour May 30 '15 at 12:03
  • I have also sent a mail to support@crashlytics.com and they told me that "Crashlytics Android logs are written asynchronously [...] We're looking at ways to improve the reliability of these async log writes and considering synchronous methods that users could choose to use" So they are working on this issue, but there's no solutions yet... – DSoldo Nov 09 '15 at 08:47
1

According to the Crashlytics docs:

To make sure that sending crash reports has the smallest impact on your user’s devices, Crashlytics logs have a maximum size of 64 KB. When a log exceeds 64 KB, the earliest logged values will be dropped in order to maintain this threshold.

Your first message will be dropped if the second message plus the first message exceed 64KB.

Manuel
  • 14,274
  • 6
  • 57
  • 130