简体   繁体   English

如何在Android中登录而不会崩溃?

[英]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. 如果仅添加日志,则在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. 我不希望崩溃日志。

Fabric crashlytics doesn't capture "non-exceptions". Fabric crashlytics不会捕获“非异常”。

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: 要使用Answers,您首先必须像这样实现它:

In your app level gradle: 在您的应用程序级别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): 在您的清单中(由于您已经在使用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: 然后,在MainActivity或Application类中,应初始化Answers,如下所示:

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. 然后,该日志将显示在Fabrics控制台中。


It's also important to note that you will soon have to move to Google Crashlytics, as Fabric is closing. 同样重要的是要注意,随着Fabric即将关闭 ,您很快将不得不使用Google Crashlytics

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

Try this. 尝试这个。 I got Log in Fabric without crash 我在没有崩溃的情况下登录了Fabric

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM