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

标签 java gradle spring-boot log4j profiles

我有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/

相关文章:

java - 端点无法解析为类型(ws 中的@Endpoint)- Eclipse 编译错误

java - 在java中的二叉树递归函数中存储计数器

java - 来自字符串的字节数组

java - 从java中的URL读取: when is a request actually sent?

java - Gradle 不会将 JNI *.so 库打包到 APK 文件中

Spring 正在失去与数据库的连接,并且无法恢复或重新连接

java - Primefaces 4.0 的 XML 命名空间

gradle - 如何让 Gradle 显示依赖冲突的来源?

gradle - 多种 gretty 配置

spring - 如何使用 Spring Boot Security 修复 Spring Boot Webflux 应用程序中的 'Invalid bean definition with name requestMappingHandlerAdapter' 错误