Open drewhamilton opened 5 years ago
Do we need to add the additional exception list post instantiation? Might be better to just offer a constructor param to allow consumer send class list, that way the list can be immutable still.
From a consumer perspective, typically you initialize Timber once and don't touch it again.
open class DebugTree(vararg ignoredClasses: Class<Any>) : Tree() {
private val fqcnIgnore = listOf(
Timber::class.java.name,
Timber.Forest::class.java.name,
Tree::class.java.name,
DebugTree::class.java.name
).plus(ignoredClasses)
Yeah, that's a better API. Happy to update if there's interest in merging this feature.
I am very interested by this :)
Yeah me too. 👍
Converted to a constructor parameter. The semantics are a bit weird now though: it's not obvious when reading DebugTree(SomeClass::class.java)
that the tree would ignore "SomeClass" for tags. I wonder if a static factory like DebugTree.withIgnoredClasses
would be more appropriate.
Converted to a constructor parameter. The semantics are a bit weird now though: it's not obvious when reading
DebugTree(SomeClass::class.java)
that the tree would ignore "SomeClass" for tags. I wonder if a static factory likeDebugTree.withIgnoredClasses
would be more appropriate.
I think that is a valid consideration, we can add a static factory to make the API more explicit.
What if we wrap Timber logs inside kotlin top level functions?
LogExtension.kt:
fun logD("message") {
Timber.d(message)
}
Then if we want to ignore it we do not access to the class. However there is an auto generated class named LogExtensionKt
that is hidden from kotlin files. So what we can do about it?
Maybe if we accept ignored classes as strings we can solve this problem but I'm not sure if its a good thing to do.
Any update on this?
Any update?
alternative plan
Fixes #180 on a per-Tree basis. Replaces #314 given the new internal tag-determination logic.
Add
DebugTree#ignoreForTagging(Class)
to allow more classes to be ignored when the tag is inferred from the stacktrace. This is useful for anyone needing to wrap Timber, e.g. for use in a Java-only module.Also changes
fqcnIgnore
from a list into a set because only itscontains
method is used.