Reputation: 43310
I'm pretty frustrated with how to make IDEA output anything from the tests to console. I've tried different versions of Scala, ScalaTest and IDEA - nothing helps. Currently my setup is: scala-2.10.0-snapshot, scalatest_2.9.1-1.6.1, idea 110.3. The project is managed by maven. Could anyone please help? I'm expecting to see something like that: http://www.scalatest.org/getting_started_with_feature_spec
Upvotes: 5
Views: 3245
Reputation: 43310
Looks like it's a problem of Idea Scala plugin. Later builds start putting some output into the console, but not everything one should expect. For latest releases of the plugin check out http://confluence.jetbrains.net/display/SCA/Scala+Plugin+Nightly+Builds+for+Nika
Upvotes: 3
Reputation: 1074
I've just been through the whole "getting punished by IDEA" thing and I have this solution for you...
Add Logback and slf4s to your POM:
<dependency>
<groupId>com.weiglewilczek.slf4s</groupId>
<artifactId>slf4s_${scala.version}</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>0.9.30</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>0.9.30</version>
</dependency>
NOTES:
I've used ${scala.version} in the slf4s artifactId - make sure you have this defined or replace it with 2.9.1 or something like that.
Also - you'll need the scala-tools repo available for dependencies too - which I'm assuming you'll have as I think you need it to compile.
Then add a file called logback.xml to your resources folder containing this:
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date,%d{HH:mm:ss.SSS},%thread,%-5level,%logger{36},%line,%msg%n</pattern>
</encoder>
</appender>
<root level="TRACE">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
My pattern there is potentially a bit weird - it's actually from a file appender that spits it out as a CSV I can open and graph in Excel easily.
Then extend the trait Logging in your app like so:
import swing._
import com.weiglewilczek.slf4s.Logging
object App extends SwingApplication with Logging {
override def startup(args: Array[String]) {
logger.info("Starting init...")
}
}
And the info message, "Starting init..." with a bunch of other stuff should appear in the console window.
Logback and slf4s are topics that I've linked to.
IMPORTANT AND AWESOME:
I can't remember what it's called but the logging methods you use to post messages all have signatures like info(message: => String) - as you can see in logger.scala.
This means the expression or block you pass to them will not get executed at all if the relevant level of logging isn't enabled in the config file.
So it only adds a method call and a flag-check to the code when it's turned off - which is pretty sweet imho :)
Hope that helps, Seth.
Upvotes: 1