如何配置gradle在不同环境中使用不同的log4j.properties文件?

时间:2016-10-17 18:26:28

标签: java gradle spring-boot log4j profiles

我有3个配置文件local,dev,prod配置文件和3个不同的log4j.properties文件。如何配置gradle使用不同的属性文件?我需要类似于How to configure maven to use different log4j.properties files in different environments

的内容

1 个答案:

答案 0 :(得分:0)

我建议您阅读Spring引导参考中的Logging部分。你真的不应该构建一个特定于环境的应用程序。您应该使用相同的工件并指定环境变量来指定该环境的唯一特征(The Twelve-Factor App - Build, Release, Run)。在这种情况下,您将创建一个应用程序,然后在使用local,dev或prod的情况下,您可以为logging.config指定一个环境变量,该变量指向不同的log4j.properties文件,类似于您指定的方式spring.profiles.active属性。

Logback的参考中甚至还有一个特殊部分,可以根据配置文件以不同方式进行日志记录。我知道你的原始问题是log4j.properties,但也许这需要看看logback。在Profile-Specific Configuration部分下,它显示您可以使用不同配置文件的部分自定义logging.config文件。例子:

<springProfile name="staging">
    <!-- configuration to be enabled when the "staging" profile is active -->
</springProfile>

<springProfile name="dev, staging">
    <!-- configuration to be enabled when the "dev" or "staging" profiles are active -->
</springProfile>

<springProfile name="!production">
    <!-- configuration to be enabled when the "production" profile is not active -->
</springProfile>
相关问题