6

I have a gradle project and the structure looks like this

>
> main (one project)
> shared (another project)
> api 
>> shared2 (another project)

main project depends on both shared and shared2 projects. Both shared and shared2 projects have a logback-test.xml in their src/test/resources folder and the main project has a logback.xml in its src/main/resources folder.

When I run the main project in eclipse using its main Application class I am expecting that only logback.xml is loaded in classpath. Instead I see warnings that multiple slf4j bindings are found and more importantly the logging settings are being applied from the logback-test.xml instead of logback.xml. Here is the folder structure for further clarification

>
> main
> > src/main/resources
> > > logback.xml
> shared
> > src/test/resources
> > > logback-test.xml
> api/shared2
> > src/test/resources
> > > logback-test.xml

In both logback-test.xml files I have enabled org.springframework debugging at DEBUG level and in logback.xml its set at INFO level. When I start the application I see the spring DEBUG logs.

Here is the sample github project https://github.com/adeelmahmood/logback-test-conf-issue

1
  • when slf4j complains that multiple slf4j bindings are found, it also gives the location of these bindings. Could you please share that warning message? Commented Mar 11, 2015 at 8:58

1 Answer 1

9

Following is the order in which logback library looks up for the configuration xml file: (from documentation)

  1. Logback tries to find a file called logback.groovy in the classpath.

  2. If no such file is found, logback tries to find a file called logback-test.xml in the classpath.

  3. If no such file is found, it checks for the file logback.xml in the classpath..

  4. If neither file is found, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console.

Hence in your case, logback finds logback-test.xml in the classpath and logs accordingly.

You can specify your own configuration file location by setting the system property named logback.configurationFile.

Sign up to request clarification or add additional context in comments.

2 Comments

but why is the logback-test file even found. When I run the application shouldnt the test classes and resources not even be available unless I am running the tests.
I am marking that as answered but I dont think it makes sense that at the time of running the non-test code, somehow test classpath is accessible as well. That is generally not the case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.