How can I use configureAndWatch method in PropertyConfigurator class in LOG4J?
1 posts in topic
Flat View  Flat View

Posted By:   Goutham_Chakilam
Posted On:   Wednesday, November 26, 2003 09:07 AM

I need to know more details about using this feature regarding changing properites in .properties file in Log4J.

For say, I am building a web app and it is webAppXXXX.WAR and it has log4j.properites file under /WEB-INF/classes directory. In this case How could I change this .properties file which is in a .WAR file and how I will configureAndwatch(XX file name) in PropertyConfigurator class works and Please can any one explain me details.

Just I want to know how we can implement re-configuring the changes made on the fly to .propertied file in to application without restarting the apps.

Thanks in advance guru's,

Re: How can I use configureAndWatch method in PropertyConfigurator class in LOG4J?

Posted By:   m_d  
Posted On:   Tuesday, December 30, 2003 05:46 AM

Well first you need to make sure that configureAndWatch(), but also just the configure() method, is called only once in the lifetime of your web application.

To accomplish this, I hav created a servlet that does just that. It only implements the init method in which it configures log4j using the property file as follows:

long refreshTime;

try {
String resreshTimeString = this.getInitParameter(LOG4J_REFRESH_TIME);
refreshTime = Long.valueOf(resreshTimeString).longValue();
} catch (NumberFormatException e) {

String fileName = getInitParameter(LOG4J_PROPERTY_CONFIG_FILE);

PropertyConfigurator.configureAndWatch(fileName, refreshTime);

Obviously both init parameters need to be configured correctly in the web.xml.

Changes in the content of the property file will now be picked up by log4j within the specified refresh time.

But be aware, if you delete a logger in the config file, the logger, including its last set level, will NOT be deleted.



About | Sitemap | Contact