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

Allow override for tag depth #314

Closed
wants to merge 4 commits into from

Conversation

drewhamilton
Copy link

Pull DebugTree.CALL_STACK_INDEX into a protected getLoggingDepth() method. This is useful for apps that wrap Timber and don't want every tag to be "TimberWrapper" or whatever. Does not affect default behavior for users who don't want/need this.

@drewhamilton
Copy link
Author

Sort of addresses #180, but only on a per-tree basis rather than a per-log basis.

Drew Hamilton added 2 commits April 16, 2018 19:49
* master:
  Fix ignored test by using INFO log instead of DEBUG log
@drewhamilton
Copy link
Author

Any interest in this? It goes a long way in allowing use of Timber with Java-only modules without requiring much change or maintenance from Timber IMO.

@tonisives
Copy link

This would be helpful for us. Currently resolved to calling Timber.tag(getTagFromStackTrace()) before logging calls.

@dvdciri
Copy link

dvdciri commented Nov 27, 2019

Is this going to be merged anytime soon? Would be very helpful when wrapping timber around your own logger, and be able still get the class name calling your custom wrapper.

@whoyawn
Copy link

whoyawn commented Dec 2, 2019

Do any of the debug tree's methods help in getting the tag from the stack trace or do we have to subclass DebugTree/get the stack trace ourselves without the api?

@drewhamilton
Copy link
Author

@whoyawn createStackElementTag is protected, so you have to subclass DebugTree to get access to it. But the call stack index it looks for is defined in package-private, final getTag, so to change how createStackElementTag is called you really have to create a completely new Tree class and copy/paste the portions of DebugTree logic you want.

This PR allows you to change that call stack index by overriding DebugTree, so you don't have to copy/paste. Though it really should take that index via constructor or setter, so you don't even have to override. I'll update it to do that if Jake shows any interest in merging this (which he probably won't because the master branch already has a completely different default tree for Timber 5).

@drewhamilton
Copy link
Author

Closing this because it's very out of date (e.g. the main branch is now in Kotlin rather than Java).

@TurKurT656
Copy link

Any workaround here? I really need this feature

@drewhamilton
Copy link
Author

You can create your own subclass of Tree in your app that behaves however you like.

@TurKurT656
Copy link

@drewhamilton But the problem is that tag is an internal field and so we can't override that.

@drewhamilton drewhamilton deleted the tag-depth branch February 10, 2022 19:25
@drewhamilton
Copy link
Author

Ah you're right, I forgot about that. #362 is the Kotlin version of this PR; it's still open.

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

Successfully merging this pull request may close these issues.

None yet

5 participants