JakeWharton / timber

A logger with a small, extensible API which provides utility on top of Android's normal Log class.
https://jakewharton.github.io/timber/docs/5.x/
Apache License 2.0
10.41k stars 959 forks source link

Allow additional ignored classes when inferring tags in DebugTree #362

Open drewhamilton opened 5 years ago

drewhamilton commented 5 years ago

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 its contains method is used.

yhartanto commented 4 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.

yhartanto commented 4 years ago
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)
drewhamilton commented 4 years ago

Yeah, that's a better API. Happy to update if there's interest in merging this feature.

tpucci commented 4 years ago

I am very interested by this :)

yhartanto commented 4 years ago

Yeah me too. 👍

drewhamilton commented 4 years ago

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.

yhartanto commented 4 years ago

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.

I think that is a valid consideration, we can add a static factory to make the API more explicit.

TurKurT656 commented 2 years ago

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.

Chesteer89 commented 2 years ago

Any update on this?

dyguests commented 4 months ago

Any update?

dyguests commented 4 months ago

alternative plan

https://github.com/dyguests/timber/releases/tag/5.0.1.1