Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to config slf4j+logback in a multi-module Maven project?

My Maven project has about seven sub-modules. Six of them packages as JARs and one as WAR.

Should I create individual logback.xml config in each module? Or should I have a "common" module that all other modules depend on, and put one single logback.xml in there? Are there any other options?

Thanks.

like image 932
scabbage Avatar asked Jan 31 '12 22:01

scabbage


2 Answers

All library JARs should use only slf4j-api dependency, and only a final application (in your case it is .war) should contain logback dependency and its configuration.

For test purposes I think easier to make <scope>test</scope> dependency to the slf4j-simple, it is simpler to use, and usually good enough for test cases.

like image 90
kan Avatar answered Nov 18 '22 20:11

kan


Assuming you wish to add logback.xml configuration file in the modules with jar packaging for testing purposes, then just place logback.xml under src/test/resources folder in each module of type 'jar'.

As @kan mentioned, the slf4j binding, e.g. slf4j-simple or logback-classic, should be in the test scope.

like image 4
Ceki Avatar answered Nov 18 '22 22:11

Ceki