You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by RB...@dtint.com on 2003/04/11 18:22:22 UTC

Configurators

Ceki/Mark,

I've a couple of doConfigure methods I wanted to add to the DOM and 
Property configurators.  I have my configuration "files" in memory as 
strings (retrieved from a database).  Neither PropertyConfigurator nor 
DOMConfigurator have a doConfigure method that I can use where I can pass 
in a String.  The new methods I'm proposing provide an InputStream to 
PropertyConfigurator (pass the string into a ByteArrayInputSream, pass 
that into doConfigure), and a Reader for DOMConfigurator (pass the string 
into a StringReader).  For consistency, it may be better to just use the 
input stream in both instances.  I'd have used a reader for both, but 
Properties objects don't have a convenient way to read Readers.

Do I have to include an apache license with this code for it to be 
submitted?

CODE: 

in DOMConfigurator.java
  /**
     Configure log4j by reading in a log4j.dtd compliant XML
     configuration Reader.

  */
  public
  void doConfigure(Reader reader, LoggerRepository repository) 
                                          throws FactoryConfigurationError 
{
    doConfigure(new InputSource(reader), repository);
  }

in PropertyConfigurator.java
  /**
         Read configuration options from an input stream <code>in</code>.
   */
  public void doConfigure(InputStream in, LoggerRepository hierarchy) {
        Properties props = new Properties();
        LogLog.debug("Reading configuration from stream " + in);

        try {
          props.load(in);
        } catch (java.io.IOException e) {
          LogLog.error(
                "Could not read configuration from stream [" + in + "].", 
e);
          LogLog.error("Ignoring configuration stream [" + in + "].");

          return;
        }

        doConfigure(props, hierarchy);
  }