Skip to content

Instantly share code, notes, and snippets.

@marc0x71
Created November 1, 2017 19:21
Show Gist options
  • Save marc0x71/85a680e493391d3e87510a32b34103e2 to your computer and use it in GitHub Desktop.
Save marc0x71/85a680e493391d3e87510a32b34103e2 to your computer and use it in GitHub Desktop.
Default Timber app
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree() {
@Override
protected String createStackElementTag(StackTraceElement element) {
return super.createStackElementTag(element) + ":" + element.getLineNumber();
}
});
} else {
Timber.plant(new ReleaseTree());
}
}
private static class ReleaseTree extends Timber.Tree {
@Override
protected boolean isLoggable(int priority) {
return !(priority == Log.VERBOSE || priority == Log.DEBUG);
}
@Override
protected void log(int priority, String tag, String message, Throwable t) {
if (!isLoggable(priority)) return;
if (priority == Log.ASSERT) {
Log.wtf(tag, message);
} else {
Log.println(priority, tag, message);
}
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment