2016-07-13 68 views
5

DebugTree記錄時,我看到類名稱,但是當我創建自定義樹時,標記爲null。這裏就是我的自定義樹是這個樣子:使用木材時標記爲空

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); 
    } 
} 
} 

然而,即使從DebugTree,獲取生成的標籤是BaseActivity,因爲它確實來自BaseActivity但我不知道是否有一種方法可以讓我得到的名稱擴展BaseActivity

回答

4

類根據傑克沃頓:

tag除非你打電話tag(String)在日誌站點或從DebugTree延長(你守爲空沒有做生產測井)。

因此,您需要在每次調用之前添加Timber.tag([class name])

請參閱github.com/JakeWharton/timber/issues/122