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

Making possible to add wrapped class name to ignore list #485

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion timber/src/main/java/timber/log/Timber.kt
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,11 @@ class Timber private constructor() {
Tree::class.java.name,
DebugTree::class.java.name
)
protected open val customIgnoredClassNameList = emptyList<String>()

override val tag: String?
get() = super.tag ?: Throwable().stackTrace
.first { it.className !in fqcnIgnore }
.first { it.className !in (fqcnIgnore+customIgnoredClassNameList) }
.let(::createStackElementTag)

/**
Expand Down
24 changes: 23 additions & 1 deletion timber/src/test/java/timber/log/TimberTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import com.google.common.truth.Truth.assertThat
import org.junit.Assert.assertTrue
import org.junit.Assert.fail
import org.robolectric.shadows.ShadowLog.LogItem
import timber.log.loggerfacade.LoggerFacade

@RunWith(RobolectricTestRunner::class)
@Config(manifest = Config.NONE)
class TimberTest {
@Before @After fun setUpAndTearDown() {
Timber.uprootAll()
}

// NOTE: This class references the line number. Keep it at the top so it does not change.
@Test fun debugTreeCanAlterCreatedTag() {
Timber.plant(object : Timber.DebugTree() {
Expand Down Expand Up @@ -304,6 +304,28 @@ class TimberTest {
.hasNoMoreMessages()
}

@Test fun debugTreeTagNameIsFacadeClassNameWhenTimberCallsAreCalledInsideFacadeClass() {
Timber.plant(Timber.DebugTree())
LoggerFacade.d("te%st")
assertLog()
.hasDebugMessage("LoggerFacade", "te%st") //tag name is LoggerFacade
.hasNoMoreMessages()
}

@Test fun debugTreeTagNameIsClassNameWhereFacadeClassIsCalled() {
val debugTree=object :Timber.DebugTree(){
override val customIgnoredClassNameList: List<String>
get() = listOf(LoggerFacade::class.java.name)
}
Timber.plant(debugTree)
LoggerFacade.d("te%st")
assertLog()
.hasDebugMessage("TimberTest", "te%st") //tag name is TimberTest
.hasNoMoreMessages()
}



@Test fun messageWithException() {
Timber.plant(Timber.DebugTree())
val datThrowable = truncatedThrowable(NullPointerException::class.java)
Expand Down
10 changes: 10 additions & 0 deletions timber/src/test/java/timber/log/loggerfacade/LoggerFacade.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package timber.log.loggerfacade

import timber.log.Timber

//This is just example facade object that uses Timber for logging
object LoggerFacade{
fun d(message: String){
Timber.d(message)
}
}