Why are log loading configurations in a different order and ignoring system properties (SBT)?

I tried to figure out my logging situation ( How to properly manage log configurations in development and production using SBT and Scala? ), And I "are you facing a funny problem.

According to the logbook documentation , a log check checks for logback-test.xml before it checks logback.xml .

I have the following files:

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

So, I realized that when running sbt test it will look at logback-test.xml . This is true in intellij (which controls the execution of the test itself), but when run from the command line, this does not seem true.

I renamed my logback.xml and turned on log debugging, and here is the output. Obviously, it searches for files in 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 suppose this is because the test resources are in the test class directory, but I have no idea how to fix this correctly.

SECOND, supplying -Dlogback.configurationFile=config/logback-#{environment}.xml does not seem to do anything, it generally ignores it.

Any thoughts?

+8
scala logging slf4j sbt logback
source share
1 answer

I assume you have no typos as this works with intellij.

Logback will try to load logback-test.xml then the clockwork one, then the normal one see this . By trying to load, I mean that the class loader will be launched (should be a test class) and will look for it in the resources. Check (for example, print) the path to your resources and make sure the xml file is there. sbt by default should make sure that your test resources are available at runtime (see here ). If you change the unmanaged build sbt resources or test the task dependencies, they may not be copied.

Finally, if you still have not found the problem (which would be strange), I believe that you should run a clean project to check if the problem persists, if it is not, you should clear the cache in intellij. Still see the problem? Sorry, I can’t help, maybe there is a problem with your installation or version of sbt?

Good luck

0
source share

All Articles