Created
November 1, 2017 19:21
-
-
Save marc0x71/85a680e493391d3e87510a32b34103e2 to your computer and use it in GitHub Desktop.
Default Timber app
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 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