Skip to content
Permalink
Browse files

Add tests for `isXEnabled` behaviors

This includes creating loggers at each of the five standard levels, so
we can run tests to check for their enablement.
  • Loading branch information...
sarahgerweck committed Jun 24, 2019
1 parent c3f80a9 commit 91445898ebd8fe46fad635105240c1231be0f058
@@ -74,5 +74,10 @@ object PlatformInit extends IPlatformInit {
}
}
Log4sConfig.addLoggerAppender("test", log4sAppender)
Log4sConfig.setLoggerThreshold("level.tr", Trace)
Log4sConfig.setLoggerThreshold("level.de", Debug)
Log4sConfig.setLoggerThreshold("level.in", Info)
Log4sConfig.setLoggerThreshold("level.wa", Warn)
Log4sConfig.setLoggerThreshold("level.er", Error)
}
}
@@ -12,6 +12,23 @@
<appender-ref ref="TEST" />
</logger>

<!-- Note: these are intentionally not named "trace", etc, in case of cross-wiring bugs -->
<logger name="level.tr" additivity="false" level="TRACE">
<appender-ref ref="TEST" />
</logger>
<logger name="level.de" additivity="false" level="DEBUG">
<appender-ref ref="TEST" />
</logger>
<logger name="level.in" additivity="false" level="INFO">
<appender-ref ref="TEST" />
</logger>
<logger name="level.wa" additivity="false" level="WARN">
<appender-ref ref="TEST" />
</logger>
<logger name="level.er" additivity="false" level="ERROR">
<appender-ref ref="TEST" />
</logger>

<root level="WARN">
<appender-ref ref="STDOUT" />
</root>
@@ -10,6 +10,11 @@ import ch.qos.logback.classic.{ Level => Lvl }
*/
class LoggerSpec extends FlatSpec with Matchers with GivenWhenThen with LoggerInit {
private[this] val testLogger = getLogger("test")
private[this] val traceLogger = getLogger("level.tr")
private[this] val debugLogger = getLogger("level.de")
private[this] val infoLogger = getLogger("level.in")
private[this] val warnLogger = getLogger("level.wa")
private[this] val errorLogger = getLogger("level.er")

behavior of "log compilation"

@@ -113,6 +118,101 @@ class LoggerSpec extends FlatSpec with Matchers with GivenWhenThen with LoggerIn
event hasData ("errorError2", Lvl.ERROR, Some(e2))
}

it should "identify trace enablement" in {
val l: Logger = traceLogger

When("threshold is trace")
l.isTraceEnabled shouldBe true

When("threshold is debug")
l.isDebugEnabled shouldBe true

When("threshold is info")
l.isInfoEnabled shouldBe true

When("threshold is warn")
l.isWarnEnabled shouldBe true

When("threshold is error")
l.isErrorEnabled shouldBe true
}

it should "identify debug enablement" in {
val l: Logger = debugLogger

When("threshold is trace")
l.isTraceEnabled shouldBe false

When("threshold is debug")
l.isDebugEnabled shouldBe true

When("threshold is info")
l.isInfoEnabled shouldBe true

When("threshold is warn")
l.isWarnEnabled shouldBe true

When("threshold is error")
l.isErrorEnabled shouldBe true
}

it should "identify info enablement" in {
val l: Logger = infoLogger

When("threshold is trace")
l.isTraceEnabled shouldBe false

When("threshold is debug")
l.isDebugEnabled shouldBe false

When("threshold is info")
l.isInfoEnabled shouldBe true

When("threshold is warn")
l.isWarnEnabled shouldBe true

When("threshold is error")
l.isErrorEnabled shouldBe true
}

it should "identify warn enablement" in {
val l: Logger = warnLogger

When("threshold is trace")
l.isTraceEnabled shouldBe false

When("threshold is debug")
l.isDebugEnabled shouldBe false

When("threshold is info")
l.isInfoEnabled shouldBe false

When("threshold is warn")
l.isWarnEnabled shouldBe true

When("threshold is error")
l.isErrorEnabled shouldBe true
}

it should "identify error enablement" in {
val l: Logger = errorLogger

When("threshold is trace")
l.isTraceEnabled shouldBe false

When("threshold is debug")
l.isDebugEnabled shouldBe false

When("threshold is info")
l.isInfoEnabled shouldBe false

When("threshold is warn")
l.isWarnEnabled shouldBe false

When("threshold is error")
l.isErrorEnabled shouldBe true
}

it should "handle MDC behavior" in {
When("doing normal logging using MDC.withCtx")
MDC.withCtx("a" -> "b") {

0 comments on commit 9144589

Please sign in to comment.
You can’t perform that action at this time.