Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With Scala 2.10.2, SBT 0.13.0, Specs2 & Play Framework 2.2.1 how can I control logging whilst running tests?

I'm getting mightily confused about the different logging frameworks being used by our Play 2 framework Scala application - and even with trial and error I've not found a way to provide a separate logging configuration file between running the application using 'run' and 'test'.

Our application is using play.api.Logger instances to output logs. We've got various other play plugins that seem to be outputting directly via logback.

So far we've been controlling log output successfully using a single conf/logger.xml (this is the logback configuration right?) file. This sets up two appenders with patterns and controls the output levels. When executing the app through 'run' absolutely no issues.

If I try and provide an alternative conf/logger-test.xml file - running with 'test' ignores it. I've tried doing:

testOptions in Test ++= Seq(
        Tests.Setup(() => {
            println("Setting logger to logger-test.xml")
            System.setProperty("logger.file", "conf/logger-test.xml")
        })
    ),

In Build.scala but that does not affect anything.

So, in an effort to understand the different components in use, http://www.playframework.com/documentation/2.2.x/SettingsLogger seems to indicate that a) play actually is using a seperate logging framework internally and b) then pushes that to logback. What I have no idea about is how to tell which of those implementations is broken.

Can anyone help me understand how play 2 logging works in this respect and through that help me fix my particular issue? From some googling it looks as if there might be problems with play with logging configuration when using 'dist' as well but I'm not there yet.

EDIT:

I'm wondering if this is the issue? Not had chance to try it yet.

like image 920
Kieran Benton Avatar asked Feb 01 '26 01:02

Kieran Benton


1 Answers

I remember struggling with the same issue. Basically, when running tests I couldn't find a way to have Play! use a different logger configuration. I ended up finding a way: I have conf/logger.xml for my production code and I added /test/resources/logger-text.xml to configure my logger when running tests.

My log configuration files follow the logback syntax for configuration. Hope that helps.

like image 143
vptheron Avatar answered Feb 03 '26 18:02

vptheron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!