使用Timber和自定义报告树无法看到Fabric中的实际崩溃

时间:2015-03-26 03:22:05

标签: android crash-reports crashlytics

我的树:

private static class CrashlyticsReportingTree extends Timber.HollowTree {

    public CrashlyticsReportingTree(Context context) {
      Fabric.with(context, new Crashlytics());
    }

    private static String maybeFormat(String message, Object... args) {
      // If no varargs are supplied, treat it as a request to log the string without formatting.
      if (args == null || args.length == 0) {
        return message;
      } else {
        return String.format(message, args);
      }
    }

    @Override
    public void e(String message, Object... args) {
      String completeMessage = maybeFormat(message, args);
      Crashlytics.logException(new Throwable(completeMessage));
    }

    @Override
    public void e(Throwable t, String message, Object... args) {
      String completeMessage = maybeFormat(message, args);
      Crashlytics.log(completeMessage);
      Crashlytics.logException(t);
    }

  }

错误报告中Fabric的第一行是

...App$CrashlyticsReportingTree.e (App.java:73)
timber.log.Timber$1.e (Timber.java:183)
timber.log.Timber.e (Timber.java:54)

为什么呢? 如何从堆栈树中删除这些行?

1 个答案:

答案 0 :(得分:3)

我使用以下Timber树向Crashlytics报告。 不知道你为什么在日志中显示timber.log.Timber.e,我的不是。 也许是因为你在日志方法中创建了一个新的Throwable?

   private static class CrashReportingTree extends Timber.HollowTree {
        @Override public void e(Throwable t, String message, Object... args) {
            if(crashlyticsEnabled) {
                Crashlytics.logException(t);
            }
        }

        @Override public void e(String message, Object... args) {
            if(crashlyticsEnabled) {
                final String formattedMessage = String.format(message, args);
                final String tag = "";
                Crashlytics.log(Log.ERROR, tag, formattedMessage);
            }
        }
    }