Rohan Patel
Rohan Patel

Reputation: 1858

How to log without crash in Android?

I have integrated Fabric for crash capturing. But in a special case, I need to just log some details on the fabric. But I didn't find any way to add a log without a crash. Each time I need to crash app to see logs.

Crashlytics.log(subStr);    
Crashlytics.logException(new RuntimeException("Exception"));

If I just add logs, I didn't see logs on Fabric. I need to explicitly throw an exception.

I am looking for a way where I can just log detail? I don't want crash logs.

Upvotes: 0

Views: 679

Answers (2)

HB.
HB.

Reputation: 4236

Fabric crashlytics doesn't capture "non-exceptions".

Only when an exception is called will it appear in your console, whether that be fatal or non-fatal.


If you want to log events, any events you want, you can use Answers for that.

To use Answers, you will first have to implement it like this:

In your app level gradle:

implementation('com.crashlytics.sdk.android:answers:1.4.7@aar') {
    transitive = true;
}

In your Manifest (I assume this will already be there since you're already using Crashlytics):

<meta-data
    android:name="io.fabric.ApiKey"
    android:value="3323d86155070b69e4558c773e7bdb6dc495cd9f"
/>

Then in your MainActivity or your Application class, you should initialize Answers, like this:

Fabric.with(this, new Answers());

Whenever you want to log something you can call it like this example:

Answers.getInstance().logCustom(new CustomEvent("Video Played")
        .putCustomAttribute("Category", "Comedy")
        .putCustomAttribute("Length", 350));

The log will then be displayed in your Fabrics console.


It's also important to note that you will soon have to move to Google Crashlytics, as Fabric is closing.

Upvotes: 1

Hitech P
Hitech P

Reputation: 103

Crashlytics.getInstance().core.logException(new RuntimeException("Exception"));

Try this. I got Log in Fabric without crash

Upvotes: 0

Related Questions