Skip to content

Instantly share code, notes, and snippets.

@talenguyen
Last active January 31, 2019 03:51
Show Gist options
  • Select an option

  • Save talenguyen/fd2ca5b4466c8e59a1a5929b561eaec8 to your computer and use it in GitHub Desktop.

Select an option

Save talenguyen/fd2ca5b4466c8e59a1a5929b561eaec8 to your computer and use it in GitHub Desktop.
CrashReportingTree logging for Timber
/** 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);
}
}
}
}
/** 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