Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

logback-test.xml and multi-module maven project

In my maven project, I've got one module depending on another and it's test code/resources:

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

Now, both modules have their own logback-test.xml, each having a specific configuration for running tests in that particular module. However, as expected, when running tests in child module, logback complains with a warning that there are multiple logback-test.xml in the path, AND does that with it's default logging configuration:

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 could I solve this problem.. I want to keep multiple configurations for each module; I guess I can't exclude one file from classpath; I really just want to logback to shut up about things I'm aware of. As you can see from last two lines, I do have whole logback package on "OFF" in my configuration, but it still proceeds to log after that point. Log pattern is also different than I have configured in either configuration.

Logback is configured and used in code via SLF4J.

When running tests in parent module, none of this is logged (neither INFO nor WARN messages), so I can't blame it on anything else but strange Logback behaviour.

like image 758
uiron Avatar asked Feb 27 '12 07:02

uiron


1 Answers

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 haven't tried this) you could use a naming convention logback-test-project.a.xml, logback-test-project.b.xml etc. and configure surefire differently in each project with -Dlogback.configurationFile=logback-test-project.a.xml.

like image 93
artbristol Avatar answered Jan 03 '23 12:01

artbristol