根据 documentation 有两种登录 Crashlytics 的方法.
Crashlytics.log(int priority, String tag, String msg);
除了写入下一个崩溃报告外,它还会使用
android.util.Log.println(priority, tag, msg)
写入 LogCat。Crashlytics.log(msg);
这只会写入 Crashlytics 崩溃报告 [而非 logcat]。
但是,第二种方法不允许我设置标签和优先级。相反,它会自动将生成的标签设置为“CrashlyticsCore”和调试优先级:
来自 Fabric 仪表板:
1 | 04:24:55:100 (UTC) | D/CrashlyticsCore ...
2 | 04:24:55:101 (UTC) | D/CrashlyticsCore ...
3 | 04:24:55:121 (UTC) | D/CrashlyticsCore ...
如何保留我的实际标签和调试值?我想我可以创建一个自定义消息,但这看起来很难看,只会弄乱 Fabric:
String output = String.format(Locale.US,
"Priority: %d; %s : %s", priority, tag, message);
Crashlytics.log(output);
最佳答案
如果您需要在 Crashlytics 中记录标签但避免在 LogCat 中使用 Crashlytics.log(int priority, String tag, String msg);
我建议启用 SilentLogger
对于 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());
关于crashlytics - 使用标签和优先级登录到 Crashlytics,而不发送到 logcat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49001291/