[
https://issues.apache.org/jira/browse/LOG4J2-658?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14107561#comment-14107561
]
Remko Popma commented on LOG4J2-658:
------------------------------------
I still think that the simplest thing is to not register the log4j shutdown
hook.
True, if the application's shutdown hook is logging a lot, uses async logging,
and has a slow appender configured (eg a database) there is a possibility not
all shutdown logs are persisted.
Should log4j now bend over backwards and use reflection and JVM implementation
details to try to make its shutdown hook run last? (By the way, are shutdown
hooks run in parallel or in sequence? Can we make the log4j2 shutdown hook
start after all other hooks are finished?)
I'm not convinced.
This is a pretty theoretical use case. Is it really a good idea to put mission
critical log messages in your shutdown hook? The shutdown hook javadocs
specifically warn against this:
{quote}
Shutdown hooks run at a delicate time in the life cycle of a virtual machine
and should therefore be coded defensively. (...) They should also not rely
blindly upon services that may have registered their own shutdown hooks and
therefore may themselves in the process of shutting down.
{quote}
The thing is, even if we did all this hacky stuff and got our shutdown hook to
run last, what does this do? Calling LoggerContext.stop() will essentially just
wait for the async logger's background thread to clear its backlog of events
remaining in the queue. However, there's no guarantee that the JVM will give us
enough time to finish all this work. Again, from the Runtime.addShutdownHook()
javadocs:
{quote}
Shutdown hooks should also finish their work quickly. (...) When the virtual
machine is terminated due to user logoff or system shutdown the underlying
operating system may only allow a fixed amount of time in which to shut down
and exit. (...)
{quote}
Shutdown hooks may not even be run at all.
So there are still no guarantees that there are no lost log messages...
If we really want to implement this, fine, but I honestly don't think there's
much point.
(sorry, this got longer than intended)
> shutdown hook called too early
> ------------------------------
>
> Key: LOG4J2-658
> URL: https://issues.apache.org/jira/browse/LOG4J2-658
> Project: Log4j 2
> Issue Type: Bug
> Components: Core
> Affects Versions: 2.0-rc1, 2.0-rc2, 2.0.2
> Reporter: Romain Manni-Bucau
> Assignee: Matt Sicker
>
> Hi
> this issue follow few mail exchanges from the commons list. Here the
> interesting part for log4j2:
> {quote}
> Here what I do (we can move it to another thread since that's 100% log4j2
> related):
> unzip apache-tomee-1.7.0-SNAPSHOT-webprofile.zip &&
> cd apache-tomee-webprofile-1.7.0-SNAPSHOT/ &&
> rm conf/logging.properties &&
> echo 'openejb.log.factory=log4j'>conf/system.properties &&
> cp ~/log4j2.xml conf/log4j2.xml &&
> cp
> ~/.m2/repository/org/apache/logging/log4j/log4j-api/2.0-rc2-SNAPSHOT/log4j-api-2.0-rc2-SNAPSHOT.jar
> lib/ &&
> cp
> ~/.m2/repository/org/apache/logging/log4j/log4j-core/2.0-rc2-SNAPSHOT/log4j-core-2.0-rc2-SNAPSHOT.jar
> lib/ &&
> cp
> ~/.m2/repository/org/apache/logging/log4j/log4j-1.2-api/2.0-rc2-SNAPSHOT/log4j-1.2-api-2.0-rc2-SNAPSHOT.jar
> lib/ &&
> ./bin/catalina.sh
> it makes server starting with log4j2 logs, if you ctrl+c logs are not
> printed. Sure it is cause context is closed too early and then loggers have
> NullConfiguration. (If I debug in java.lang.ApplicationShutdownHooks#runHooks
> to wait all hooks exec it works)
> {quote}
> Basically the issue is that when shutting down with ctrl+C some logs are
> swallowed.
--
This message was sent by Atlassian JIRA
(v6.2#6252)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]