Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring boot using logback-test.xml instead of logback.xml

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

like image 573
adeelmahmood Avatar asked Mar 10 '15 04:03

adeelmahmood


1 Answers

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.

like image 153
Mithun Avatar answered Oct 19 '22 12:10

Mithun