[
https://issues.apache.org/jira/browse/LOG4J2-658?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14104719#comment-14104719
]
Romain Manni-Bucau commented on LOG4J2-658:
-------------------------------------------
Potential "solutions":
1) try to move context.stop from run() to join() in
LoggerContext#ShutdownThread (doesn't fully solve the issue but can help if we
have some luck that container hook is joined before log4j one)
2) cleanup everything which needs cleanup (means for console appender for
instance it would be a noop, i think the same for file would work ensuring we
flush it, for jdbc appender we can't help that much since we need to close
everything)
3) the best but clearly more impacting: integrate with containers when possible
(tomcat using a Listener, tomee using @Observes and extension mecanism, etc...)
4) a bit hacky but should work: instead of Runtime shutdown hook and thanks to
sun.misc.SharedSecrets.getJavaLangAccess().registerShutdownHook(x, y) use
directly java.lang.Shutdown to add the hook after Application hooks (0, 1, 2
are taken so 9 (=MAX_SYSTEM_HOOKS - 1) should be fine. If not we can add a noop
shutdown hook and then wrap by reflectionjava.lang.Shutdown#hooks[1] to call
real log4j shutdown hook after applications ones)
last is the one with the best easiness/efficiency ratio IMHO.
> shutdown hook called too early
> ------------------------------
>
> Key: LOG4J2-658
> URL: https://issues.apache.org/jira/browse/LOG4J2-658
> Project: Log4j 2
> Issue Type: Bug
> Affects Versions: 2.0-rc1, 2.0-rc2
> Reporter: Romain Manni-Bucau
>
> 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]