How to get logging working in scala unit tests with testng, slf4s, and logback

后端 未结 4 943
被撕碎了的回忆
被撕碎了的回忆 2020-12-30 23:51

I\'m new to Scala, and not that familiar with recent developments in Java, so I am having what I assume is a basic problem.

I\'m writing some Scala code, and testing

4条回答
  •  一向
    一向 (楼主)
    2020-12-31 00:51

    I think it's because SBT runs the tests in parallel and some initialization code in Slf4j is not thread safe (!). See http://jira.qos.ch/browse/SLF4J-167 ... it's been reported more than 2 years ago!

    As a workaround I initialize Slf4j by loading the root logger before the tests run. To do so just add this to your SBT settings:

    testOptions += Setup( cl =>
       cl.loadClass("org.slf4j.LoggerFactory").
         getMethod("getLogger",cl.loadClass("java.lang.String")).
         invoke(null,"ROOT")
    )
    

提交回复
热议问题