Created
July 3, 2016 17:55
-
-
Save sembozdemir/2fc99f0f1b77da3c634005c29e6a6cce to your computer and use it in GitHub Desktop.
Initializing Timber in the Application class
This file contains hidden or 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 App extends Application { | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
Timber.plant(BuildConfig.DEBUG | |
? new Timber.DebugTree() | |
: new CrashReportingTree()); | |
Fabric.with(this, new Crashlytics()); | |
FirebaseAnalytics.getInstance(this); | |
// other things... | |
} | |
private class CrashReportingTree extends Timber.Tree { | |
private static final String CRASHLYTICS_KEY_PRIORITY = "priority"; | |
private static final String CRASHLYTICS_KEY_TAG = "tag"; | |
private static final String CRASHLYTICS_KEY_MESSAGE = "message"; | |
@Override | |
protected void log(int priority, String tag, String message, Throwable throwable) { | |
if (priority == Log.VERBOSE || priority == Log.DEBUG) { | |
return; | |
} | |
Throwable t = throwable != null | |
? throwable | |
: new Exception(message); | |
// Crashlytics | |
Crashlytics.setInt(CRASHLYTICS_KEY_PRIORITY, priority); | |
Crashlytics.setString(CRASHLYTICS_KEY_TAG, tag); | |
Crashlytics.setString(CRASHLYTICS_KEY_MESSAGE, message); | |
Crashlytics.logException(t); | |
// Firebase Crash Reporting | |
FirebaseCrash.logcat(priority, tag, message); | |
FirebaseCrash.report(t); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment