Add getDefaultTag() so a Tree can have its own custom tag generation logic#208
Add getDefaultTag() so a Tree can have its own custom tag generation logic#208dbartel wants to merge 5 commits intoJakeWharton:trunkfrom
Conversation
| * If no tag is explicitly set, then the tree will fall back to this tag. | ||
| * @return The default tag for this tree | ||
| */ | ||
| protected String getDefaultTag() { |
There was a problem hiding this comment.
Let's annotate with @Nullable
| final ThreadLocal<String> explicitTag = new ThreadLocal<>(); | ||
|
|
||
| String getTag() { | ||
| private String getTag() { |
There was a problem hiding this comment.
This was probably package private to remove the creation of synthetic accessor methods.
|
|
||
| @Test public void logsWithCustomTag() { | ||
| Timber.plant(new Timber.DebugTree() { | ||
| @Override |
There was a problem hiding this comment.
nit: should be on the same line
|
|
||
| Timber.d("Test with custom tag"); | ||
| assertLog() | ||
| .hasDebugMessage("CUSTOMTAG", "Test with custom tag"); |
There was a problem hiding this comment.
continuation indent is 4 spaces and this could also easily get into one line
|
|
||
| @Test public void logsWithCustomTagOverridden() { | ||
| Timber.plant(new Timber.DebugTree() { | ||
| @Override |
| Timber.tag("NewTag").d("Tag manually set"); | ||
|
|
||
| assertLog() | ||
| .hasDebugMessage("NewTag", "Tag manually set"); |
| assertLog() | ||
| .hasDebugMessage("CUSTOMTAG", "multiple tags") | ||
| .hasDebugMessage("DIFFERENTTAG", "multiple tags"); | ||
|
|
| Timber.d("multiple tags"); | ||
|
|
||
| assertLog() | ||
| .hasDebugMessage("CUSTOMTAG", "multiple tags") |
There was a problem hiding this comment.
let's do continuation indent of 4
|
|
||
| @Test public void logsWithMultipleTreesMultipleTags() { | ||
| Timber.plant(new Timber.DebugTree() { | ||
| @Override |
| }); | ||
|
|
||
| Timber.plant(new Timber.DebugTree() { | ||
| @Override |
|
@vanniktech thanks for reviewing this. I don't plan on working on this guy anymore since I don't use Timber or really do much Android development at all. I'll leave it open if you want to contribute changes to it, otherwise feel free to close it out. |
- Annotate getDefaultTag() as @nullable - General clean-up/styling changes
|
@vanniktech OK I guess I lied, I found a little free time and was still thinking about this for some reason & your feedback wasn't too much, I made changes according to your comments and pushed 'em up |
Closes #118
This allows a Tree to set its own tag by overriding the method getDefaultTag(). Currently, a Tree can only have a tag set if Timber.tag is explicitly called.
Note that the current tag behavior still should work the same way - if Timber.tag gets called, that tag will be used over the default.