The tag is null when using Timber

When DebugTree logs, I see the class name, however, when I create my own tree, the null tag. Here's what my regular tree looks like:

 public class CrashlyticsTree extends Timber.Tree { private static final String CRASHLYTICS_KEY_PRIORITY = "priority"; private static final String CRASHLYTICS_KEY_TAG = "tag"; private static final String CRASHLYTICS_KEY_MESSAGE = "message"; @Override protected boolean isLoggable(int priority) { if (priority == Log.VERBOSE || priority == Log.DEBUG || priority == Log.INFO) { return false; } // only log WARN(Timber.w), ERROR(Timber.e), or WTF(Timber.wtf) return true; } @Override protected void log(int priority, @Nullable String tag, @Nullable String message, @Nullable Throwable t) { if(User.CurrentUser.isLoggedIn()){ Crashlytics.setUserIdentifier(Long.toString(User.CurrentUser.getUserId())); } Crashlytics.setInt(CRASHLYTICS_KEY_PRIORITY, priority); Crashlytics.setString(CRASHLYTICS_KEY_TAG, tag); Crashlytics.setString(CRASHLYTICS_KEY_MESSAGE, message); if (t == null) { Crashlytics.logException(new Exception(message)); } else { if(!TextUtils.isEmpty(message)){ Crashlytics.log(priority, tag, message); } Crashlytics.logException(t); } } } 

However, even from DebugTree the BaseActivity tag is BaseActivity , because it comes from BaseActivity , but I was wondering if there is a way to get the name of the class that extends BaseActivity

+5
source share
1 answer

According to Jake Wharton:

tag is null if you do not call tag(String) to the log site or cannot from DebugTree (which you should not do for logging).

Therefore, you need to add Timber.tag([class name]) before each call.

See github.com/JakeWharton/timber/issues/122

+4
source

All Articles