Android / Timber / Crashlytics tree to send logs in production
public class CrashlyticsTree extends Timber.Tree {
public CrashlyticsTree(Context context, DeviceInfo deviceInfo) {
Fabric.with(context, new Crashlytics());
// Put some debug variables for every crash
// CrashlyticsCore core = Crashlytics.getInstance().core;
// core.setString("Git SHA", BuildConfig.GIT_SHA);
}
@Override
protected void log(int priority, String tag, String message, Throwable t) {
if (priority == Log.VERBOSE && !"release".equals(BuildConfig.BUILD_TYPE)) {
//Dont log verbose messages and avoid not release builds to send crash to crashlytics
return;
}
CrashlyticsCore core = Crashlytics.getInstance().core;
core.log(Log.ERROR, tag, message);
if (t != null && priority == Log.ERROR) {
core.logException(t);
}
}
}
public class SkempiApp extends Application {
@Override
public void onCreate() {
super.onCreate();
if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree());
} else {
Timber.plant(new CrashlyticsTree(this, new DeviceInfo(this)));
}
}
}