package org.apache.log4j;

import org.apache.log4j.spi.LoggerRepository;
import org.apache.log4j.helpers.LogLog;
/**
 * <p>Title: WatchConfigurator Extends {@link PropertyConfigurator} to enable PropertyWatchdog functionality for Default Initialization </p>
 * <p>Description: use log4j.configuratorClass=org.apache.log4j.WatchConfigurator log4j.configuration.delay=delay
 * to avoid server start/stop for configuration reload </p>
 *
 * <p>Example:  -Dlog4j.configuration=file:/conf/Log4j.properties  -Dlog4j.configuratorClass=org.apache.log4j.WatchConfigurator -Dlog4j.configuration.delay=3</p>
 * <p>Copyleft: Roga and Copyta 2002</p>
 * @author Sergey Pomtykin
 * @version 1.0
 */
public class WatchConfigurator extends PropertyConfigurator{
public static final String INHERITED ="inherited";
  public void doConfigure(java.net.URL configURL, LoggerRepository hierarchy) {
      String configFilename =   configURL.getFile();
      LogLog.debug("got file name from URL\"" + configFilename +"\" ");
      PropertyWatchdog pdog = new PropertyWatchdog(configFilename);
      String del = System.getProperty("log4j.configuration.delay");
      long delay =3;
      if (del!=null) {
        try {
          delay = Long.parseLong(del);
        }catch (Exception ex) {/*forget it*/
          LogLog.error("log4j.configuration.delay mast be valid long ("+del+")",ex);
        };
      };
      pdog.setDelay(delay);
      LogLog.debug("delay set to \"" + delay +"\" ");
      pdog.start();
  }
}

