Skip to content

Instantly share code, notes, and snippets.

@sembozdemir
Created July 3, 2016 17:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sembozdemir/2fc99f0f1b77da3c634005c29e6a6cce to your computer and use it in GitHub Desktop.
Save sembozdemir/2fc99f0f1b77da3c634005c29e6a6cce to your computer and use it in GitHub Desktop.
Initializing Timber in the Application class
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