Log to Crashlytics with tag and priority without also sending to logcat

我怕爱的太早我们不能终老 提交于 2019-12-10 09:37:28

问题


There are two ways to log to Crashlytics according to the documentation.

  1. Crashlytics.log(int priority, String tag, String msg);

    In addition to writing to the next crash report, it will also write to the LogCat using android.util.Log.println(priority, tag, msg).

  2. Crashlytics.log(msg);

    which will only write to the Crashlytics crash report [not logcat].

However, this second method does not allow me to set a tag and priority. Instead it automatically sets the resulting tag as "CrashlyticsCore" and priority to debug:

From Fabric dashboard:

1   |   04:24:55:100 (UTC)  |   D/CrashlyticsCore ...
2   |   04:24:55:101 (UTC)  |   D/CrashlyticsCore ...
3   |   04:24:55:121 (UTC)  |   D/CrashlyticsCore ...

How can I keep my actual tag and debug value? I suppose I could create a custom message but this seems ugly and would just clutter up Fabric:

String output = String.format(Locale.US, 
    "Priority: %d; %s : %s", priority, tag, message);
Crashlytics.log(output);

回答1:


If you need to log tags in Crashlytics but avoid them in LogCat using Crashlytics.log(int priority, String tag, String msg); I would recommend to enable SilentLogger for Fabric:

// Create Crashlytics Kit which doesn't trace crashes in debug mode
final Crashlytics crashlyticsKit = new Crashlytics.Builder().core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build()).build();

// Use SilentLogger instead of DefaultLogger to avoid writing into LogCat 
Fabric.with(new Fabric.Builder(this).kits(crashlyticsKit).logger(new SilentLogger()).build());



来源:https://stackoverflow.com/questions/49001291/log-to-crashlytics-with-tag-and-priority-without-also-sending-to-logcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!