问题描述
我想为Eclipse和Maven(surefire插件)中的单元测试设置不同的默认logback配置。基本上,我希望在测试期间生成的任何日志都发送到Eclipse中的控制台或Maven的文件。目前,我有一个logback-test.xml有两个追加者。
我认为该解决方案涉及为两个类路径添加不同的logback-test.xml。但是我该如何做呢?在maven中有一些手册很可能(例如在一个配置文件中),但需要手动更改Eclipse(跨越许多项目)将非常烦人。
您可以随时使用系统属性 logback.configurationFile
来覆盖logback配置文件查找。
对于Maven,您可以将以下内容添加到 maven-surefire-plugin
的配置部分:
< systemPropertyVariables>
< logback.configurationFile> $ {basedir} /src/test/resources/logback-maven.xml</logback.configurationFile>
< / systemPropertyVariables>
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.
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>
这篇关于如何加载Maven / Surefire和Eclipse的不同对数配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!