Last active
January 31, 2019 03:51
-
-
Save talenguyen/fd2ca5b4466c8e59a1a5929b561eaec8 to your computer and use it in GitHub Desktop.
CrashReportingTree logging for Timber
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
| /** A tree which logs important information for crash reporting. */ | |
| class CrashReportingTree extends Tree { | |
| @Override public boolean isLoggable(int priority, @Nullable String tag) { | |
| return priority >= INFO; | |
| } | |
| @Override protected void log(int priority, String tag, Throwable t, String message) { | |
| if (priority == Log.VERBOSE || priority == Log.DEBUG) { | |
| return; | |
| } | |
| FakeCrashLibrary.log(priority, tag, message); | |
| if (t != null) { | |
| if (priority == Log.ERROR) { | |
| FakeCrashLibrary.logError(t); | |
| } else if (priority == Log.WARN) { | |
| FakeCrashLibrary.logWarning(t); | |
| } | |
| } | |
| } | |
| } |
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
| /** Not a real crash reporting library! */ | |
| public final class FakeCrashLibrary { | |
| public static void log(int priority, String tag, String message) { | |
| // TODO add log entry to circular buffer. | |
| } | |
| public static void logWarning(Throwable t) { | |
| // TODO report non-fatal warning. | |
| } | |
| public static void logError(Throwable t) { | |
| // TODO report non-fatal error. | |
| } | |
| private FakeCrashLibrary() { | |
| throw new AssertionError("No instances."); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment