[
https://issues.apache.org/jira/browse/LOG4J2-1098?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14718119#comment-14718119
]
Robin Jansohn edited comment on LOG4J2-1098 at 8/28/15 8:00 AM:
----------------------------------------------------------------
Are you sure? IMHO this is the relevant code:
{code}private void setUpShutdownHook() {
if (shutdownCallback == null) {
final LoggerContextFactory factory = LogManager.getFactory();
if (factory instanceof ShutdownCallbackRegistry) {
LOGGER.debug(SHUTDOWN_HOOK_MARKER, "Shutdown hook enabled.
Registering a new one.");
try {
this.shutdownCallback = ((ShutdownCallbackRegistry)
factory).addShutdownCallback(new Runnable() {
@Override
public void run() {
final LoggerContext context = LoggerContext.this;
LOGGER.debug(SHUTDOWN_HOOK_MARKER, "Stopping
LoggerContext[name={}, {}]", context.getName(),
context);
context.stop();
}
@Override
public String toString() {
return "Shutdown callback for LoggerContext[name="
+ LoggerContext.this.getName() + ']';
}
});
} catch (final IllegalStateException ise) {
LOGGER.fatal(SHUTDOWN_HOOK_MARKER, "Unable to register
shutdown hook because JVM is shutting down.");
} catch (final SecurityException se) {
LOGGER.error(SHUTDOWN_HOOK_MARKER, "Unable to register
shutdown hook due to security restrictions");
}
}
}
}{code}
Looks to me like the shutdown hook is really registered?!
EDIT: OK, debugged a little further, the addShutdownCallback method returns
null if the shutdown hook is disabled.
{code}@Override
public Cancellable addShutdownCallback(final Runnable callback) {
return SHUTDOWN_HOOK_ENABLED ?
shutdownCallbackRegistry.addShutdownCallback(callback) : null;
}{code}
was (Author: jansohn):
Are you sure? IMHO this is the relevant code:
{code}private void setUpShutdownHook() {
if (shutdownCallback == null) {
final LoggerContextFactory factory = LogManager.getFactory();
if (factory instanceof ShutdownCallbackRegistry) {
LOGGER.debug(SHUTDOWN_HOOK_MARKER, "Shutdown hook enabled.
Registering a new one.");
try {
this.shutdownCallback = ((ShutdownCallbackRegistry)
factory).addShutdownCallback(new Runnable() {
@Override
public void run() {
final LoggerContext context = LoggerContext.this;
LOGGER.debug(SHUTDOWN_HOOK_MARKER, "Stopping
LoggerContext[name={}, {}]", context.getName(),
context);
context.stop();
}
@Override
public String toString() {
return "Shutdown callback for LoggerContext[name="
+ LoggerContext.this.getName() + ']';
}
});
} catch (final IllegalStateException ise) {
LOGGER.fatal(SHUTDOWN_HOOK_MARKER, "Unable to register
shutdown hook because JVM is shutting down.");
} catch (final SecurityException se) {
LOGGER.error(SHUTDOWN_HOOK_MARKER, "Unable to register
shutdown hook due to security restrictions");
}
}
}
}{code}
Looks to me like the shutdown hook is really registered?!
> log4j.shutdownHookEnabled=false from log4j-web ignored?
> -------------------------------------------------------
>
> Key: LOG4J2-1098
> URL: https://issues.apache.org/jira/browse/LOG4J2-1098
> Project: Log4j 2
> Issue Type: Bug
> Components: Web/Servlet
> Affects Versions: 2.3
> Reporter: Robin Jansohn
>
> In the documentation it says for the System Property
> 'log4j.shutdownHookEnabled':
> {quote}
> Overrides the global flag for whether or not a shutdown hook should be used
> to stop a LoggerContext. By default, this is enabled and can be disabled on a
> per-configuration basis. When running with the log4j-web module, this is
> automatically disabled.
> {quote}
> I included the log4j-web module into my Maven project so the shutdown hook
> should be disabled. During initialization I can see in the debug messages
> that this is not the case:
> {quote}
> DEBUG Starting LoggerContext\[name=31484215\] from configuration at null
> DEBUG Starting LoggerContext\[name=31484215,
> org.apache.logging.log4j.core.LoggerContext@1836523\] with configuration
> XmlConfiguration\[location=C:\app\apache-tomcat-8.0.24\wtpwebapps\webapp\WEB-INF\classes\log4j2.xml\]...
> DEBUG *Shutdown hook enabled. Registering a new one.*
> DEBUG Starting configuration
> XmlConfiguration\[location=C:\app\apache-tomcat-8.0.24\wtpwebapps\webapp\WEB-INF\classes\log4j2.xml\]
> \[...\]
> {quote}
> During shutdown (more specifically the contextDestroyed method of the
> ServletContextListener) I try to log some messages but the Logger is already
> shut down and therefore swallows all log messages (see LOG4J2-658).
> Do I need to do something else to disable the shutdown hook?
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]