Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions timber/src/main/java/timber/log/Timber.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ class Timber private constructor() {
}

/** A [Tree] for debug builds. Automatically infers the tag from the calling class. */
open class DebugTree : Tree() {
private val fqcnIgnore = listOf(
open class DebugTree(vararg ignoredClasses: Class<*>) : Tree() {
private val fqcnIgnore = setOf(
Timber::class.java.name,
Timber.Forest::class.java.name,
Tree::class.java.name,
DebugTree::class.java.name
)
).plus(ignoredClasses.map { it.name })

override val tag: String?
get() = super.tag ?: Throwable().stackTrace
Expand Down
11 changes: 11 additions & 0 deletions timber/src/test/java/timber/log/TimberTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ class TimberTest {
.hasNoMoreMessages()
}

@Test fun debugTreeDoesNotUseIgnoredClassForTag() {
val tree = Timber.DebugTree(ThisIsAReallyLongClassName::class.java)
Timber.plant(tree)

ThisIsAReallyLongClassName().run()

assertLog()
.hasDebugMessage("TimberTest", "Hello, world!")
.hasNoMoreMessages()
}

@Test fun debugTreeCustomTag() {
Timber.plant(Timber.DebugTree())
Timber.tag("Custom").d("Hello, world!")
Expand Down