Created
November 4, 2015 02:20
-
-
Save danielgomezrico/18268c9963936a4e44f7 to your computer and use it in GitHub Desktop.
Android / Timber / Crashlytics tree to send logs in production
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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