解决方法
首先,你可能喜欢在测试模式下禁用日志记录的一些背景。这是Guillame Bort在游戏论坛中对问题的回答(见
this thread):
The logger is disabled in test mode for Now because it was causing an
huge PermGen space leak when running tests. But we are working to run
tests in a forked JVM so we will enable it again soon.
作为解决方法,我创建了我自己的记录器这样(Scala代码):
import play.api.{Play,LoggerLike,Logger} import org.slf4j.LoggerFactory import org.slf4j.impl.SimpleLoggerFactory object MyLogger extends LoggerLike { val factory = if (Play.isTest(Play.current)) { new SimpleLoggerFactory() } else { LoggerFactory.getILoggerFactory } val redirectDebugToInfo = factory.isinstanceOf[SimpleLoggerFactory] val logger = factory.getLogger("application") def apply(name: String): Logger = new Logger(factory.getLogger(name)) def apply[T](clazz: Class[T]): Logger = new Logger(factory.getLogger(clazz.getCanonicalName)) // this method is to make debug statements to show up in test mode override def debug(m: => String) = { if (redirectDebugToInfo) { info(m) } else { super.debug(m) } } }
我不知道这个代码关于PermGen泄漏的一般行为,但到目前为止我没有这个问题。
要使其工作,您需要添加此依赖关系:
"org.slf4j" % "slf4j-simple" % "1.6.4"