ppkarwasz commented on issue #1267:
URL: 
https://github.com/apache/logging-log4j2/issues/1267#issuecomment-1419412636

   @schotten,
   
   Logging in a Spring Boot application is configured at least twice:
   
    * when the `SpringApplication` class is loaded (that is what you see in 
your stacktrace). This process is described in [automatic 
configuration](https://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration)
 and does **not** have access to Spring's environment (that didn't start yet),
    * after the `ApplicationEnvironmentPreparedEvent` is fired (cf. [lifecycle 
of a Spring Boot 
application](https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.spring-application.application-events-and-listeners)).
 This process is specific to Spring Boot, **has** access to Spring's 
environment and uses the `log4j2-spring.xml` file (falling back on `log4j2.xml` 
if such a file does not exist).
   
   If you want to use Spring's enviroment to configure your logging system you 
have to options:
   
   1. Create two files: `log4j2.xml` and `log4j2-spring.xml`. The first one 
will be used during the bootstrap phase of your application and can not use 
Spring's environment. The second one will be used, when your application is up 
and running.
   2. Stick to a single configuration file and use 
[arbiters](https://logging.apache.org/log4j/2.x/manual/configuration.html#Arbiters)
 to provide multiple versions of your "solver-service" appender:
   ```lang-xml
   <Select>
       <SpringProfile name="dev">
           <File name="solver-service" 
fileName="${spring:log4j.solver.service.path}" append="false">
               <EcsLayout serviceName="${spring:log4j.solver.service.name}" 
serviceVersion="${spring:log4j.solver.service.version}"  
serviceEnvironment="${spring:log4j.solver.service.enviroment}"/>
           </File>
       </SpringProfile>
       <DefaultArbiter>
           <Null name="solver-service"/>
       </DefaultArbiter>
   </Select>


-- 
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