How do I load different logback configuration for Maven/Surefire and Eclipse
Asked Answered
O

1

4

I want to have different default logback configurations for my unit tests in Eclipse and Maven (surefire plugin). Basically, I want any logs generated during tests to be sent to the console in Eclipse or to a file for Maven.

Currently, I have a single logback-test.xml that has both appenders.

I think the solution involves adding a different logback-test.xml for the two classpaths. But how do I do that? Having something manual in maven is likely ok (in a profile for example), but requiring a manual change to Eclipse (across lots of projects) would be extremely annoying.

Orthogonal answered 18/9, 2015 at 18:21 Comment(0)
B
12

You can always override logback configuration file lookup using the system property logback.configurationFile.

For Maven, you can add the following to the configuration section of the maven-surefire-plugin:

<systemPropertyVariables>
    <logback.configurationFile>${basedir}/src/test/resources/logback-maven.xml</logback.configurationFile>
</systemPropertyVariables>
Boldface answered 18/9, 2015 at 21:16 Comment(1)
Just want to add note that might be useful to one who had made all as said in accepted answer but still don't get logback configuration file in charge: Problem could be in dependency. If you have slf4j-api-simple-*.jar in classpath it will not use logback configuration file. Just remove it. Here is original: https://mcmap.net/q/1021917/-logback-is-not-using-configuration-fileHolle

© 2022 - 2024 — McMap. All rights reserved.