This maybe a Incorrect documentation about Log4j2 help in link https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.logging.log4j2-extensions

The extensions supersede the [Spring Boot support](https://logging.apache.org/log4j/2.x/log4j-spring-boot/index.html) provided by Log4J. You should make sure not to include the org.apache.logging.log4j:log4j-spring-boot module in your build.

that means 'not include the org.apache.logging.log4j:log4j-spring-boot module'? as that, Profile setting is not working.

Comment From: wilkinsona

This should work so I don't think it's a documentation problem. It's more likely to be a bug I think. I could also be a usage error but I can't tell as you haven't shared any information about how you have configured Log4j2. Note that you need to use a log4j2-spring.xml file as log4j2.xml is loaded too early, preventing the use of Spring Boot's extensions. If this doesn't help you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: RayTigerZ

I use log4j2-spring.xml with springboot 2.7.x, when exclude log4j-spring-boot module, log as: ERROR Error processing element SpringProfile ([Root: null]): CLASS_NOT_FOUND

log4j2-spring.xml content:

<SpringProfile name="!prod">
    <AppenderRef ref="Console"/>
</SpringProfile>

However application run in prod or dev profile, do not log in console

Comment From: RayTigerZ

In Log4j2 website, clearly state the need for including log4j-spring-boot module, but springboot document do not , that makes me wonder

Comment From: wilkinsona

Spring Boot's Log4j2 extensions were introduced in Spring Boot 3.0 but you're using 2.7. The docs for Spring Boot 2.7 are available here: https://docs.spring.io/spring-boot/docs/2.7.x/reference/html/. Your link above was to https://docs.spring.io/spring-boot/docs/current/reference/html/. The current URL links to the latest released version of Spring Boot. At the time of writing that's 3.1.5.

Comment From: RayTigerZ

I understand what you're saying, but nothing helpful to setting log4j2 with springprofile in 2.7.x document.

Comment From: RayTigerZ

Could add the part of log4j2 springprofile setting in 2.7.x document

Comment From: wilkinsona

There's nothing to document in Spring Boot's 2.7.x documentation as it isn't a Spring Boot feature in that version. You should use org.apache.logging.log4j:log4j-spring-boot with Spring Boot 2.7.x and refer to Log4j2's documentation to learn about the Log4j2 feature.

Comment From: RayTigerZ

ok, Thank you for your answer.

Comment From: RayTigerZ

and it is excellent to add this log4j2 enhancement into SpringBoot 3.0