8

I've been trying to sort out my logging situation (How to properly manage logback configrations in development and production using SBT & Scala?), and I've run across a funny problem.

According to the logback documentation, logback checks for logback-test.xml before it checks for logback.xml.

I have the following files:

  • src/main/resources/logback.xml
  • src/test/resources/logback-test.xml

So I figured that when running sbt test, it would look to the logback-test.xml. This is true in intellij (which manages test execution itself), but does not seem to be true when running from the command line.

I renamed my logback.xml and turned on logback debugging, and here is the output. Clearly it's looking for the files in the reverse order:

14:58:21,203 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [/home/rathboma/Projects/personal/beekeeper/src/main/resources/logback.xml]
14:58:21,206 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
14:58:21,206 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback-test.xml] at [file:/home/rathboma/Projects/personal/beekeeper/target/scala-2.10/test-classes/logback-test.xml]

I'm speculating that it's because the test resources are in the test-classes directory, but I have no idea how to properly fix this.

SECONDLY, supplying -Dlogback.configurationFile=config/logback-#{environment}.xml doesn't seem to do anything, it toally ignores it.

Any thoughts?

Community
  • 1
  • 1
Matthew Rathbone
  • 8,144
  • 7
  • 49
  • 79
  • It seems like -Dlogback.configurationFile now is /home/.../resources/logback.xml and your property was ignored. How did you specify this property for sbt? could you please show your build.sbt? – dk14 Dec 20 '14 at 04:41
  • 1
    try adding this to your build.sbt : avaOptions in Test += "-Dlogback.configurationFile=src/main/resources/logback-test.xml" – philwalk Feb 18 '16 at 19:55

1 Answers1

0

I assume you don't have any typos as it works with intellij.

Logback will try to load logback-test.xml then the groovy one then the normal one see this. By try to load I mean it will get the class loader to the class running (should be the test class) and look for it in the resources. Check (by print for example) the path to your resources and verify the xml file is there. sbt by default should make sure your test resources are available during test execution (see here). If you changed your build sbt's unmanaged resources or test task dependencies it might no get copied.

Finally if you still did not find the problem (which would be weird) I believe you should start a clean project to check if the problem persists, if it doesnt you should clean your cache in intellij. Still see a problem? sorry can't help, maybe a problem with your sbt installation or version?

Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35
Eytan
  • 728
  • 1
  • 7
  • 19