Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I properly 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 :)

like image 506
alamar Avatar asked May 08 '09 10:05

alamar


People also ask

What are Appenders in Log4j?

Appenders. Apache log4j provides Appender objects which are primarily responsible for printing logging messages to different destinations such as consoles, files, sockets, NT event logs, etc. Each Appender object has different properties associated with it, and these properties indicate the behavior of that object.

Where is Log4j configuration file?

The file is named log4j. properties and is located in the $DGRAPH_HOME/dgraph-hdfs-agent/lib directory. The file defines the ROLLINGFILE appenders for the root logger and also sets the log level for the file.

How do you change the log level in Log4j 2?

You can set a logger's level with the class Configurator from Log4j Core. BUT be aware that the Configurator class is not part of the public API. If you wish to change the root logger level, do something like this : LoggerContext ctx = (LoggerContext) LogManager.


1 Answers

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?

like image 118
kgiannakakis Avatar answered Sep 27 '22 21:09

kgiannakakis