You don't need to jump through this many hoops to get this behavior - there
is an easier way to achieve dynamic, run-time re-configuration using
standard config files.  Specifically, you don't need to roll your own file
listener - Log4J already has one.  To do this, you subclass FileWatchdog and
the appropriate PropertyConfigurator.  For example, in our apps, we subclass
FileWatchdog and DOMConfigurator.  Then, you override doOnChange() and
configureAndWatch(), in your FileWatchdog sub-class and your
PropertyConfigurator sub-class, respectively.  In the PropertyConfigurator
sub-class's configureAndWatch() method, you set things up to use your
FileWatchdog sub-class (instead of a standard one), and in the doOnChange()
method of your FileWatchdog class, you call
BasicConfigurator.resetConfiguration().  In your application, you then need
to initialize Log4J by using your PropertyConfigurator class instead of the
standard one, i.e.;
"M2TraceDomConfigurator.configureAndWatch(configFile,configReloadDelay);"
and not "DOMConfigurator.configureAndWatch(configFile,configReloadDelay);".

Below are code snippets for the relevant spots from the implementation we're
using here - works fine.  This question has already been answered at least
once on this list, primarily by Ceki and Jim Moore - you should check the
list archives for more details.

Cheers,
Mark

public class M2TracePropertyWatchdog extends FileWatchdog{

<blah, blah, blah>

public void doOnChange() {
     BasicConfigurator.resetConfiguration();
     new DOMConfigurator().doConfigure(filename,
Category.getDefaultHierarchy());
   }

<blah, blah, blah>
}

public class M2TraceDomConfigurator extends DOMConfigurator {

<blah, blah, blah>

public static void configureAndWatch(String configFilename, long delay) {
    M2TracePropertyWatchdog pDog = new
M2TracePropertyWatchdog(configFilename);
    pDog.setDelay(delay);
    pDog.start();
  }

<blah, blah, blah>
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to