AAkira / Napier

Logging library for Kotlin Multiplatform
Apache License 2.0
820 stars 36 forks source link

Add a way to remove Antilog #18

Closed yshrsmz closed 5 years ago

yshrsmz commented 5 years ago

Like Timber's Timber#uprootAll(), it would be great if we have an option to remove already-added Antilogs.

In my case, if I try to use Napier in a Test and the test class has more than one test cases, Napier.base() is called multiple times, so same Antilog is added multiple times. Thus the same log is printed numerous times.

class LogTest {

  @BeforeTest
  fun setup() {
    // this is called once per a test case, so same Antilog is added multiple times.
    Napier.base(DebugAntilog())
  }

  @AfterTest
  fun tearDown() {
    // Napier.clearAntilog() // we need this!
  }

  @Test
  fun test1() {
    Napier.d("test1")
    // stdout:
    // test1
  }

  @Test
  fun test2() {
    Napier.d("test2")
    // stdout:
    // test2
    // test2
  }
}
AAkira commented 5 years ago

Thank you for your suggestion! I added the function in Napier 0.0.7.

You can remove an antilog by calling Napier.takeLogalitm().

yshrsmz commented 5 years ago

Thanks a lot for the quick update!

One quick question, Is takeLogalitm an intentional name? Quick googling suggests 'logarithm' instead of 'logaritm' 😄

AAkira commented 5 years ago

Yes, I noticed after I merged it.😂 Thank you for reporting. I already overwrote.😅