Log4J: FATAL exception on shutdown hook, can't figure out why
Log4j2 try to use shutdown hook to close the logging service properly.
Shutdown hooks are executed in parallel and that's why the exception is not systematic.
There is a bug report regarding this problem.
You can disable shutdown hook in your configuration file :
<configuration shutdownHook="disable" ...>
Also see this link on log4j2's page:
https://logging.apache.org/log4j/2.x/manual/webapp.html
If you include this dependency, it will not try to add a shutdown hook.
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>${log4j.version}</version>
</dependency>
As already mentioned here log4j-web
is the jar for this problem. It worked without any problem for jetty-9.2.1.v20140609
.
libraryDependencies += "org.apache.logging.log4j" % "log4j-web" % "2.5"
If you check the log4j-web (upto v2.9), it has log4j.shutdownHookEnabled=false
But with Servlet 3.0
and Tomcat 7.0.73
, had to remove log4j from jarsToSkip
key of conf/catalina.properties
.
Strange things might happen. As for me, I am deploying two .war
s, both using Non blocking Logger
, worked for one service but not for the other. Tomcat 7
/Websphere 8
restart cleaned it up though.
Reason for need to clean up logging resource
is described in Using Log4j 2 in Web Applications -
when the
Servlet Container
shuts down or the web app is undeployed, It's important for logging resources to be properly cleaned up (database connections closed, files closed, etc.).Because of the nature of
ClassLoader
s within web apps, Log4j resources cannot be cleaned up through normal means. Log4j must be "started" when the web app deploys and "shut down" when the web app undeploys.
Please read this official doc - Using Log4j 2 in Web Containers, its helpful.