alamar
alamar

Reputation: 19353

How do I properly shut down Log4j, closing all Appenders and, therefore, files

My servlet-based web-app sometimes fails to close Log4j log files when redeployed, leaking to file descriptor leakage and occassionally leading to servlet-contained dying from 'too many open files'.

I have a ContextListener, what should I put into its contextDestroyed() to tell log4j to shut down and release all resources?

Quick skim over javadocs revealed Hierachery class with shutdown() method. I have no idea on how to actually get the current Hierachery, and the javadoc states this class has no user-serviceable components inside :)

Upvotes: 15

Views: 17756

Answers (2)

Ulrik
Ulrik

Reputation: 765

I had the same problem but my solution required two steps:

First, I had to call LogManager.shutdown() from a servlets destroy() method.

Then I had to fix the close() method of our own Appender implementation (which is a subclass of AppenderSkeleton), so that it properly closes the appenders from getAllAppenders().

Upvotes: 1

kgiannakakis
kgiannakakis

Reputation: 104196

Try this:

org.apache.log4j.LogManager.shutdown();

However, the problem you are experiencing is strange and shouldn't be happening. What JVM, container, log4j version are you using?

Upvotes: 19

Related Questions