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

╄→гoц情女王★ 提交于 2019-12-10 15:55:12

问题


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.


回答1:


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>


来源:https://stackoverflow.com/questions/32658635/how-do-i-load-different-logback-configuration-for-maven-surefire-and-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!