Skip to content

Instantly share code, notes, and snippets.

@danielgomezrico
Created November 4, 2015 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielgomezrico/18268c9963936a4e44f7 to your computer and use it in GitHub Desktop.
Save danielgomezrico/18268c9963936a4e44f7 to your computer and use it in GitHub Desktop.
Android / Timber / Crashlytics tree to send logs in production
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)));
}
}
}
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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment