logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From RB...@dtint.com
Subject Configurators
Date Fri, 11 Apr 2003 16:22:22 GMT
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);
  }
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message