How can I get spring.profiles.active value in log4j2.xml

Viewed 29

While running my Spring Boot Application, I am passing --spring.profiles.active=qa

/user/MyApp --spring.profile.active=qa

This qa value I will change based on my env.

I need to get this qa value in my log4j2.xml

Already tried : ${sys:spring.profiles.active}. It didn't work

1 Answers

You need to use the Spring Lookup for that. Then you can retrieve the comma-separated list of active profiles with:

${spring:profiles.active}

Remark: Since Spring's Environment is available only after Spring Boot reconfigures Log4j2, the Spring lookup is not available in the first phases of your application's startup.

Related