Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Timber logger service wrapper for Janet ActionService
public class TimberServiceWrapper extends ActionServiceWrapper {
private final String serviceTag;
public TimberServiceWrapper(ActionService actionService) {
this(actionService, null);
}
public TimberServiceWrapper(ActionService actionService, String tag) {
super(actionService);
if (TextUtils.isEmpty(tag)) serviceTag = actionService.getClass().getSimpleName();
else serviceTag = tag;
}
private Timber.Tree timber() {
return Timber.tag(serviceTag);
}
@Override protected <A> boolean onInterceptSend(ActionHolder<A> holder) {
return false;
}
@Override protected <A> void onInterceptStart(ActionHolder<A> holder) {
timber().i("Action started: %s", holder.action());
}
@Override protected <A> void onInterceptCancel(ActionHolder<A> holder) {
timber().i("Action canceled: %s", holder.action());
}
@Override protected <A> void onInterceptProgress(ActionHolder<A> holder, int progress) {
timber().i("Action progress = %d: %s",progress, holder.action());
}
@Override protected <A> void onInterceptSuccess(ActionHolder<A> holder) {
timber().i("Action succeeded: %s", holder.action());
}
@Override protected <A> boolean onInterceptFail(ActionHolder<A> holder, JanetException e) {
timber().w(e, "Action failed: %s", holder.action());
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment