java - 在生产版本中包含不同的 logback.xml

标签 java maven logback

我使用 Maven 进行构建,并希望使用 logback-debugging.xml 进行开发,但将另一个 logback-info.xml 打包到最终产品中。

最佳答案

我想出了以下 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

关于java - 在生产版本中包含不同的 logback.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46157041/

相关文章:

java - Logback RollingFileAppender 中 "append"的选项是什么?

spring - 使用 Spring Logback 在不同路径配置 Kubernetes 日志

Java Thread.Join() 方法不等待线程完成

java - JUnit 5 测试未触发并且测试未显示在测试运行程序中

java - 类别上的 SLF4J log4j NoSuchMethodError

maven - 使用 Maven 创建多个配置文件 jar

java - 升级到 2.x 时,org.refcodes.console.ConsoleSugar 中缺少 switsh 和 helpSwitch 方法

Java 检查给定的小时和分钟是否位于两个日期的小时和分钟之间

java - 如何在文本文件中附加多个文本

java - 在运行时从java中的另一个进程获取初始化的静态对象