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

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,
Goutham

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) {
refreshTime = DEFAULT_RERESH_TIME;
}

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.


Grtz,

Marcel.

About | Sitemap | Contact