16

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.

scabbage
  • 1,412
  • 2
  • 15
  • 27

2 Answers2

13

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.

kan
  • 28,279
  • 7
  • 71
  • 101
  • 1
    Indeed, libraries intended for wide distribution should only depend on slf4j-api. However, not all jars are libraries. Thus, although depending on slf4j-simple is a valid option, it is not necessarily a better option than depending on logback-classic. – Ceki Feb 01 '12 at 13:18
  • @Ceki In `test` you are free to use any dependencies you wish. Each library module could have own test dependencies, they don't conflict anyway. Hence if it is enough (and it is usually), use `simple` to Keep It SSimple. – kan Feb 01 '12 at 14:48
  • Using the test scope is a good idea. All I am saying is that depending on slf4j-simple (in test scope) is OK but so is depending on logback-classic (in test scope) in modules of type 'jar'. – Ceki Feb 01 '12 at 18:24
4

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.

Ceki
  • 26,753
  • 7
  • 62
  • 71