Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tag is null #122

Closed
brescia123 opened this issue Feb 5, 2016 · 9 comments
Closed

tag is null #122

brescia123 opened this issue Feb 5, 2016 · 9 comments

Comments

@brescia123
Copy link

When I extend Timber.Tree and override the log method I get passed a null tag:

@Override
protected void log(int priority, String tag, String message, Throwable t) {
   if (priority == Log.VERBOSE || priority == Log.DEBUG || priority == Log.INFO) {
      return;
   }
   // tag is null
   Log.println(priority, tag, message);
}
@SimonVT
Copy link

SimonVT commented Feb 5, 2016

Are you calling Timber#tag?

@brescia123
Copy link
Author

No, why I have to call it?

@SimonVT
Copy link

SimonVT commented Feb 5, 2016

Because that's what sets the tag.

@JakeWharton
Copy link
Owner

The tag is null unless you call tag(String) at the log site or extend from DebugTree (which you shouldn't do for production logging).

@brescia123
Copy link
Author

Thank you!

@tir38
Copy link

tir38 commented Apr 5, 2018

(I'm not 100% certain what all DebugTree does so take with a grain of salt)

There is a way around this. You can use DebugTree in release builds as long as you are careful what you do inside log(...). As long as you don't call Android's Log class and you don't pass up to super you should be fine. Logs won't end up in logcat).

The use case I had was still wanting to send tag to crash reporting tool.

public class ReleaseTree extends Timber.DebugTree{

    @Override
    protected void log(int priority, String tag, String message, Throwable t){
        super.log(...); // Don't do this
        android.util.Log.xyz(...); // Don't do this

        // tag will not be null
        sentToCrashReportingTool(priority, tag, message, t);
    }
}

@jguerinet
Copy link

@JakeWharton is there any big downside in repurposing the DebugTree tag getter code for a tree used in production? Similar to what @tir38 is proposing. The goal obviously being having those tags when logging to a crash reporting library without having to define them everywhere.

Thanks

@JakeWharton
Copy link
Owner

JakeWharton commented Oct 12, 2018 via email

@jguerinet
Copy link

Fair enough. Thanks for the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants