Heisenbug. ClassCastException SubstituteLoggerFactory
Closed this issue · 1 comments
d10xa commented
Sometimes following code fails:
LoggerFactory.getILoggerFactory
.asInstanceOf[LoggerContext]
.getLogger("ru.d10xa.jadd")
.setLevel(Level.DEBUG)
with:
java.lang.ClassCastException: org.slf4j.helpers.SubstituteLoggerFactory
cannot be cast to ch.qos.logback.classic.LoggerContext
at ru.d10xa.jadd.LoggingUtil$.rootLogger(LoggingUtil.scala:17)
at ru.d10xa.jadd.LoggingUtil$.quiet(LoggingUtil.scala:25)
d10xa commented
Temporary fix with pattern matching
LoggerFactory.getILoggerFactory match {
case l: LoggerContext =>
l.getLogger("ru.d10xa.jadd").setLevel(Level.DEBUG)
case l: SubstituteLoggerFactory =>
def logger = l.getLogger("ru.d10xa.jadd")
println(s"SubstituteLoggerFactory used. Can not enable debug mode ${logger.getClass}")
}