By default all Logger
output, visible when an application is running, is mute when the application is tested.
How to force the debugs, infos etc. to be shown in the specs2
reports?
If it is specific to a certain application, then the application logger can be set to DEBUG. Steps: 1) Go to System Configuration -> Platform Configuration -> Logging . 2) Select Action -> Manage Appenders.
debug . This combination of a configurable logging level and logging statements within your program allow you full control over how your application will log its activity.
First off, you may like some background why logging is disabled in test mode. This was Guillame Bort's answer to a question in the play forum (see 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.
As a workaround, I created my own logger like this (Scala code):
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) } } }
I don't know how this code behaves regarding the PermGen leak in general, but so far I didn't have that problem. To make it work you need to add this dependency:
"org.slf4j" % "slf4j-simple" % "1.6.4"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With