You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Pomytkin, Sergey" <se...@attws.com> on 2002/07/30 05:07:52 UTC

Default Initialization with "configureAndWatch"

I start using Log4j from 1.2beta4
Bay the way, I really like it and even wrote little article to convince
colleagues use Lo4j instead of home-grown System.out's 
http://sergeypomytkin.boom.ru/Log4j.doc

Idea of configuring from environment (vs. from main entry point) vital for
me - some of my projects have multiple entry point like Servlets and console
apps in same project.
I fail to find way in 1.2beta4 to "configureAndWatch" using Default
Initialization.. So, quick fix it by writing my WatchConfigurator expecting
something like it embedded in 1.2 or later version.

I guess it was wrong assumption at least I didn't find how to do it from
documentation and mailing list ARChives
except this idea 
http://marc.theaimsgroup.com/?l=log4j-dev&m=102264988227469&w=2
to put it into config file (that is way better than my solution).

So, do I miss something or this problem not solved?



PS: if it's the case welcome to use/modify code below.

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 0.1
 */
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();
  }
}

Sergey Pomytkin
cell 425 241 2782
desk 425 288 7127


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>