【问题标题】:How to configure gradle to use different log4j.properties files in different environments?如何配置gradle在不同环境下使用不同的log4j.properties文件?
【发布时间】:2016-10-17 18:26:27
【问题描述】:
【问题讨论】:
标签:
java
gradle
spring-boot
log4j
profiles
【解决方案1】:
我建议您阅读 Spring boot 参考中关于 Logging 的部分。您真的不应该构建特定于环境的应用程序。您应该使用相同的工件并指定环境变量来指定该环境的独特特征 (The Twelve-Factor App - Build, Release, Run)。在这种情况下,您将创建一个应用程序,然后在使用 local、dev 或 prod 的情况下,您可以为 logging.config 指定一个环境变量,该变量指向不同的 log4j.properties 文件,类似于您指定 @ 987654325@财产。
在 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>