Skip to content

Instantly share code, notes, and snippets.

@jmcd
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmcd/d60a7fd51cd4be9e5019 to your computer and use it in GitHub Desktop.
Save jmcd/d60a7fd51cd4be9e5019 to your computer and use it in GitHub Desktop.
import android.os.Handler;
import android.widget.TextView;
import timber.log.Timber;
public class TextViewTimberDebugTree extends Timber.DebugTree {
private final static long UNINITIALIZED_DEBUG_START_TIME = -1;
private TextView textView;
private Handler handler;
private long debugStartTime = UNINITIALIZED_DEBUG_START_TIME;
public TextViewTimberDebugTree(TextView textView, Handler handler) {
this.textView = textView;
this.handler = handler;
}
@Override
protected void log(int priority, final String tag, final String message, Throwable t) {
final long time = this.getTime();
this.handler.post(new Runnable() {
@Override
public void run() {
TextViewTimberDebugTree.this.textView.append(String.format("%d %s %s\n", time, tag, message));
}
});
}
@Override
protected String createStackElementTag(StackTraceElement element) {
String className = super.createStackElementTag(element);
return String.format("%s.%s", className, element.getMethodName());
}
private long getTime() {
if (this.debugStartTime == UNINITIALIZED_DEBUG_START_TIME) {
this.debugStartTime = System.currentTimeMillis();
}
return System.currentTimeMillis() - this.debugStartTime;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment