[英]Using Spring @Profile to load log4j2 xml configuration instead of maven <profile>
目前我正在使用這樣的 maven 加載我的 log4j2 配置
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<resources>
<resource>
<directory>src/main/resources/env-dev</directory>
</resource>
</resources>
</build>
</profile>
<profile>
<id>test</id>
<build>
<resources>
<resource>
<directory>src/main/resources/env-test</directory>
</resource>
</resources>
</build>
</profile>
<profile>
<id>prd</id>
<build>
<resources>
<resource>
<directory>src/main/resources/env-prd</directory>
</resource>
</resources>
</build>
</profile>
</profiles>
但這需要我為每個環境建立新的戰爭,這是我想避免的。 有沒有辦法讓我使用 Spring @Profile 注釋來加載 log4j2 配置?
我還沒有嘗試過 log4j2,但我相信您可以使用屬性logging.config
提供配置文件位置。
舉個例子:-
在application-dev.properties
文件中放置以下內容。 可以使用 -Dspring.profiles.active=dev 激活此配置文件
logging.config=/env-test/log4j2.xml
在application-prd.properties
文件中放置以下內容。 可以使用 -Dspring.profiles.active=prd 激活此配置文件
logging.config=/env-prd/log4j2.xml
將兩個配置文件放在 src/main/resources 目錄中。
注意:如果使用 YAML,它會更方便,因為它們可以放在單個配置文件中,使用---
分隔文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.