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

   > There are two reasons why I opened this issue:
   > 
   >     1. Please, consider this code `XXX.shutdown()`. Will you expect that 
`XXX` will work after executing the code? I won't. That's why I spent several 
hours trying to understand why my log files are empty. Imagine, that XXX is 
your computer. What will you say if it works after you shutdown it?
   
   I see your point, thanks for explaining it. IMHO the main problem is a 
misunderstanding of what `LogManager#shutdown` does. The Javadoc says:
   
   > Shutdown using the LoggerContext appropriate for the caller of this method.
   
   which does not say much. ;-) What in reality happens is that **only** the 
logger context appropriate for the caller shuts down and is unregistered. This 
does not prevent the `LoggerContextFactory` from creating new logger contexts 
if `LogManager.getLogger()` is called again, which happens in your case.
   
   >     2. As I understand (I may be wrong here!) JRE specs doesn't say where 
JRE writes last log message. If I am right then Log4j2 should support all 
possible cases. For example, if in Java 22+ they will add log message AFTER  
`Shutdown#runHooks` then all log files of all `log4j2` users will be empty. 
That's it.
   
   Your logs are empty, because you specified `append="false"` in your 
configuration file. This is not the default value and is not the value I'd 
recommend: on most systems opening files in append mode allows multiple 
applications to write to the same file at the same time; for reasonable sizes 
of the messages the `write` calls are even atomic and log lines are not broken 
in half.
   
   Although there is no guarantee, I find it very unlikely future JREs will log 
anything after the shutdown hooks started: logging must also stop at a certain 
point.
   


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