ppkarwasz opened a new issue, #1783:
URL: https://github.com/apache/logging-log4j2/issues/1783

   ## Description
   
   In a Spring Boot application Log4j Core is initialized **at least** twice:
    - the first initialization is the static Log4j Core initialization 
(Spring's 
[`Environment`](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/core/env/Environment.html)
 is not available yet),
    - the second initialization is performed programmatically by Spring Boot as 
soon as it creates an `Environment`. It can use the same configuration file as 
the first one.
   
   On the other hand the builder of 
[`SpringProfileArbiter`](https://github.com/apache/logging-log4j2/blob/2.x/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/SpringProfileArbiter.java)
 returns `null` if no Spring `Environment` is present, which causes (handled) 
`NullPointerException`s in `AbstractConfiguration#processConditionals` or 
`AbstractConfiguration#processSelect`.
   
   Since the arbiter logic itself accepts a `null` environment, we should 
remove the following null-check:
   ```java
   environment = (Environment) 
loggerContext.getObject(Log4j2SpringBootLoggingSystem.ENVIRONMENT_KEY);
   if (environment == null) {
       LOGGER.warn("Cannot create Arbiter, no Spring Environment provided");
       return null;
   }
   ```
   
   The fix should be propagated to the [Spring Boot 
project](https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringProfileArbiter.java).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to