Ismael Di Vita Ismael Di Vita - 1 year ago 120
Android Question

Log method name and line number in Timber

Is possible log the current line number and method name using the Timber library

Expected LogCat result:

07-31 20:19:00.248 28998-28998/ismaeldivita.myapp I/[L:22] [M:onResume] [C:HomeActivity]: Praise the log!

Answer Source

Answering my own question.

Just create a new DebugTree class

public class MyDebugTree extends Timber.DebugTree {    
    protected String createStackElementTag(StackTraceElement element) {
        return String.format("[L:%s] [M:%s] [C:%s]",

And plant your Tree in Timber:

public class App extends Application {
    public void onCreate(){
        if (BuildConfig.DEBUG) {
           Timber.plant(new MyDebugTree());
        } else {
           //TODO plant your Production Tree
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download