我有3个本地,个人资料,产品简介和3个不同的log4j.properties文件。如何配置gradle以使用不同的属性文件?我需要与此How to configure maven to use different log4j.properties files in different environments类似的东西
最佳答案
我建议您阅读Spring引导引用中有关Logging的部分。您确实不应该构建特定于环境的应用程序。您应该使用相同的 Artifact ,并指定环境变量以指定该环境的唯一特征(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>
关于java - 如何配置gradle在不同的环境中使用不同的log4j.properties文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40093221/