Logback-test.xml and the multi-module maven project

In my maven project, I have one module depending on another, and it checks the code / resources:

... <scope>test</scope> <type>test-jar</type> ... 

Now both modules have their own logback-test.xml, each of which has a specific configuration for running tests in this particular module. However, as expected, when running tests in the child module, the log blocks a warning that there are several logback-test.xml in the path, and does this with the default logging setting:

 08:44:17,528 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy] 08:44:17,530 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback-test.xml] at [file:path/to/my/project/module2/logback-test.xml] 08:44:17,532 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback-test.xml] occurs multiple times on the classpath. 08:44:17,533 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback-test.xml] occurs at [file:/C:/path/to/my/project/module2/logback-test.xml] 08:44:17,533 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback-test.xml] occurs at [file:/C:/path/to/my/project/module1/logback-test.xml] 08:44:17,636 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set 08:44:17,647 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender] 08:44:17,653 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT] 08:44:17,692 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property 08:44:17,764 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to WARN 08:44:17,764 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT] 08:44:17,765 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [com.myproject] to TRACE 08:44:17,765 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [ch.qos.logback] to OFF 08:44:17,768 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@5b0a485c - Registering current configuration as safe fallback point 

I wonder how I can solve this problem. I want to save several configurations for each module; I think I cannot exclude one file from the classpath; I just want me to forget to shut up about the things that I know about. As you can see from the last two lines, I have the full log package set to “OFF” in my configuration, but it still goes to the log after this point. The log template is also different from what I configured in any configuration.

Redundancy is configured and used in code through SLF4J.

When tests are run in the parent module, none of them are registered (neither INFO nor WARN messages), so I can not blame him for anything other than the strange behavior of Logback.

+6
source share
1 answer

You can exclude logback-test.xml from the test jar

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>test-jar</goal> </goals> <configuration> <excludes> <excludes>logback-test.xml</excludes> </excludes> </configuration> </execution> </executions> </plugin> 

Or (I have not tried this), you could use the naming convention logback-test-project.a.xml , logback-test-project.b.xml , etc. and configure surefire differently in each project using -Dlogback.configurationFile=logback-test-project.a.xml .

+5
source

Source: https://habr.com/ru/post/909430/


All Articles