我在我的DebugTree
应用程序中使用了木材。我要将所有消息记录到Firebase崩溃报告中。
Timber.plant(object : Timber.DebugTree() {
override fun log(priority: Int, tag: String?, message: String?, t: Throwable?) {
FirebaseCrash.logcat(priority, tag, message)
}
})
但是现在所有消息都被复制到logcat中,如下所示
11-07 17:08:07.823 V/GoogleApiClientPlugin: Connected to GooglePlayClient
11-07 17:08:07.823 V/GoogleApiClientPlugin: Connected to GooglePlayClient
11-07 17:08:07.824 V/NearbyForegroundService: connected to Google Api Client
11-07 17:08:07.824 V/NearbyForegroundService: connected to Google Api Client
我不想用if (BuildConfig.DEBUG) { ... }
来保护调用,因为日志也应该附加到在调试构建中发生的崩溃。
Fabric具有相同的行为,但我可以将记录器设置为静默.logger(new SilentLogger())
,以防止重复的日志消息。是否有针对Firebase的API?
发布于 2016-11-08 20:37:46
只需使用FirebaseCrash.log(String mess)方法来记录消息
下面是我使用的代码:
public class FirebaseBone extends Dog.Bone {
@Override
String getTag() {
return "Shadow";
}
@Override
protected boolean isLoggable(String tag, int priority) {
return super.isLoggable(tag, priority);
}
@Override
protected void log(int priority, String tag, String message, Throwable t) {
String sb = getPriority(priority) +
(TextUtils.isEmpty(tag) ? "" : ("/" + tag)) +
": " +
message;
FirebaseCrash.log(sb);
if (t != null) {
FirebaseCrash.report(t);
}
}
private String getPriority(int priority) {
switch (priority) {
case Log.ASSERT:
return "A";
case Log.DEBUG:
return "D";
case Log.ERROR:
return "E";
case Log.INFO:
return "I";
case Log.VERBOSE:
return "V";
case Log.WARN:
return "W";
default:
return "?";
}
}
}
https://stackoverflow.com/questions/40469485
复制相似问题