This issue is really around adding clarification in the documentation with the usage of log4j2-spring.xml vs log4j2.xml. The documentation says the following: When possible, we recommend that you use the -spring variants for your logging configuration (for example, logback-spring.xml rather than logback.xml). If you use standard configuration locations, Spring cannot completely control log initialization.

What I'm looking for is clarification on what you actually lose by using log4j2.xml. I'd like to avoid the rename if there is no functional difference but want to be able to understand the impact of doing so. I did also notice that the configuration file automatically provided uses log4j2.xml for the name: https://github.com/spring-projects/spring-boot/tree/v2.1.1.RELEASE/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/log4j2

Comment From: wilkinsona

For Log4j2, it's not really anything more than the documentation already states. If you name your file log4j2.xml, we cannot prevent Log4j from finding the file before Spring Boot has had a chance to initialise Log4j. As such, we cannot completely control logging initialisation. For the record, if you're using Logback, you lose a bit more as the use of logback-spring.xml is required for our Logback extensions.

I'm not sure what we can do to clarify the documentation here. If you have a suggestion we'd be happy to consider it. Thanks.

Comment From: celdridge91190

Ah ok I may have missed that detail on the page I was looking at ( I apologise for not including it, I will see if I can find the one I pulled what I pasted in). What I'd like to know is what side effect occurs if Spring is unable to initialize log4j2? Is there a benefit to allowing that rather than allowing log4j2 to initialize automatically?

Comment From: wilkinsona

Is there a benefit to allowing that rather than allowing log4j2 to initialize automatically?

We're rather going round in circles here.

If the file is named log4j.xml, Log4j2 will find it as soon as a logger is requested. This will likely happen before any of the code in Boot's Log4J2LoggingSystem and associated logging initialisation has run. In other words, a period of your application's startup will happen without any of Boot's logging configuration having been applied. Unfortunately, I don't have time to enumerate everything that it does and, therefore, everything that you'll miss out on for a period of time, but you can learn what it does by reading the documentation and looking at the code. You can then make a call if there's any benefit for your specific circumstances.

Comment From: sluongng

I find myself asking this very same question after wandering around internet guides on how to setup log4j2 configuration with spring... so I suggest a bit additional clarification in the documentation would be quite helpful

Additionally, I want to know if alternative configuration file formats, i.e. log4j2.yaml, should/can also apply the "-spring" naming convention?

Comment From: ravenblackdusk

one important thing you lose if you don't add '-spring' is the ability to override configurations via spring properties(like application.yml). for example logging.level.org.springframework: debug won't work.

Comment From: abccbaandy

@ravenblackdusk I'm not sure it's version problem or something, but I test log4j2.yml with spring boot 2.3.0. logging.level.org.springframework: debug work well.