Last active
August 29, 2015 14:26
-
-
Save jmcd/d60a7fd51cd4be9e5019 to your computer and use it in GitHub Desktop.
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
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