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

   @PavelTurk,
   
   The main problem in your code is that you are calling `LogManager#shutdown` 
in your main method, instead of using a shutdown hook. Somewhere between Java 
17 and Java 21 (cf. [source 
code](https://github.com/openjdk/jdk/blob/12723688ca49d379d43fd0fd0e55a28afe299687/src/java.base/share/classes/java/lang/Shutdown.java#L159))
 a `Shutdown#logRuntimeExit` method was introduced that runs **after** your 
explicit `LogManager#shutdown` call, but **before** any proper shutdown hooks.
   
   Therefore you need:
   
   - remove the `LogManager#shutdown` call and use a proper shutdown hook. 
Log4j Core **does** automatically install one, unless it detects a servlet 
environment. In the latter case you can force a shutdown hook by setting the 
property `log4j2.shutdownHookEnabled` to `true` (cf. 
[documentation](https://logging.apache.org/log4j/2.x/manual/configuration.html#system-properties)).
 The easiest way to do it is through a `log4j2.component.properties` file.
   
   **Remark**: Instead of using a `logging.properties` file to configure 
`System.Logger`, consider using `log4j-jpl`. In order to do so just add:
   
   ```xml
   <dependency>
     <groupId>org.apache.logging.log4j</groupId>
     <artifactId>log4j-jpl</artifactId>
     <scope>runtime</scope>
   </dependency>
   ```
   
   and enjoy a full Log4j Core experience.


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