2017-09-11 40 views

回答

0

Logback以特定顺序搜索配置文件(请参见the docs here)。它看起来的第一个地方是在你的classpath中有一个叫做logback-test.xml的文件。由于您使用的是maven,请将该文件包含在您的测试/资源目录中。通过这种方式,当您运行任何测试时,将使用logback-test.xml文件。对于您的生产代码,请在您的主目录/资源目录中包含logback.xml。

0

我想出了以下Maven配置:

<profile> 
     <id>development</id> 
     <activation> 
      <property> 
       <name>dev</name> 
      </property> 
     </activation> 
     <build> 
      <resources> 
       <resource> 
        <filtering>true</filtering><!-- if it is neccessary --> 
        <directory>src/main/logging/develop</directory><!-- from --> 
        <targetPath>${project.build.outputDirectory}</targetPath><!-- to --> 
        <includes><!-- what --> 
         <include>logback.xml</include> 
        </includes> 
       </resource> 
       <resource> 
        <directory>src/main/resources</directory> 
        <includes> 
         <include>**/*</include> 
        </includes> 
       </resource> 
      </resources> 
     </build> 
    </profile> 
</profiles> 

在Maven的设置文件,我们可以激活每个默认的配置文件:

<settings> 
    [..] 
    <activeProfiles> 
    <activeProfile>development</activeProfile> 
    </activeProfiles> 
    [..] 
</settings> 

另一种方式是默认的配置文件配置移到“正常”的POM构建部分。

要激活开发配置文件,请通过命令行(例如, mvn package -Ddev

相关问题