[...]
That is my understanding. I believe that filters are also not configurable from property files.

Wouldnt it be useful to be able to do this?
The attached patch adds a mechanism to the PropertySetter which
tries to instanciate a class from the property value, if the parameter
of the setter is not a primitive type. With this patch, I was able
to configure the RollingFileAppender as follows:

log4j.appender.testAppender=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.testAppender.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy
log4j.appender.testAppender.triggeringPolicy.maxFileSize=100
log4j.appender.testAppender.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy
log4j.appender.testAppender.rollingPolicy.fileNamePattern=RFA-test%i.log
log4j.appender.testAppender.rollingPolicy.activeFileName=RFA-test.log
log4j.appender.testAppender.Append=false
log4j.appender.testAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.testAppender.layout.ConversionPattern=%m\n

Drawback of my fast and dirty solution is that part of the
PropertyConfigurator behaviour is duplicated in the PropertySetter,
to allow configuring the sub component.

Regards,

        Andreas

--
Andreas Fester
mailto:[EMAIL PROTECTED]
WWW: http://www.littletux.net
ICQ: 326674288
--- logging-log4j-1.3alpha-6.org/src/java/org/apache/log4j/config/PropertySetter.java	2005-01-20 20:43:18.000000000 +0100
+++ logging-log4j-1.3alpha-6/src/java/org/apache/log4j/config/PropertySetter.java	2005-10-03 14:51:28.000000000 +0200
@@ -20,6 +20,7 @@
 import org.apache.log4j.*;
 import org.apache.log4j.helpers.OptionConverter;
 import org.apache.log4j.spi.ComponentBase;
+import org.apache.log4j.spi.OptionHandler;
 
 import java.beans.BeanInfo;
 import java.beans.IntrospectionException;
@@ -118,7 +119,7 @@
           continue;
         }
 
-        setProperty(key, value);
+        setProperty(key, value, properties, prefix);
       }
     }
   }
@@ -138,7 +139,7 @@
      @param name    name of the property
      @param value   String value of the property
    */
-  public void setProperty(String name, String value) {
+  public void setProperty(String name, String value, Properties props, String prefix) {
     if (value == null) {
       return;
     }
@@ -153,7 +154,7 @@
         "No such property [" + name + "] in " + objClass.getName() + ".");
     } else {
       try {
-        setProperty(prop, name, value);
+        setProperty(prop, name, value, props, prefix);
       } catch (PropertySetterException ex) {
         getLogger().warn(
           "Failed to set property [" + name + "] to value \"" + value + "\". ",
@@ -161,6 +162,10 @@
       }
     }
   }
+  
+  public void setProperty(String name, String value) {
+     setProperty(name, value, null, null);
+  }
 
   /**
       Set the named property given a [EMAIL PROTECTED] PropertyDescriptor}.
@@ -170,7 +175,7 @@
       @param name The named of the property to set.
       @param value The value of the property.
    */
-  public void setProperty(PropertyDescriptor prop, String name, String value)
+  public void setProperty(PropertyDescriptor prop, String name, String value, Properties props, String prefix)
     throws PropertySetterException {
     Method setter = prop.getWriteMethod();
 
@@ -195,8 +200,29 @@
     }
 
     if (arg == null) {
-      throw new PropertySetterException(
-        "Conversion to type [" + paramTypes[0] + "] failed.");
+      // Maybe an object setter?
+
+      //      appender =
+      Object instance = OptionConverter.instantiateByClassName(
+              value, paramTypes[0], null);
+      if (instance != null) {
+          getLogger().debug("Setting component [{}] to [{}].", name, instance);
+          setComponent(name, instance);
+
+          PropertySetter componentPS = new PropertySetter(instance);
+          // componentPS.setLoggerRepository(repository);
+          String x = prefix + name + ".";
+          componentPS.setProperties(props, x); // prefix + "." + name + ".");
+          //activateOptions(instance);
+          if (instance instanceof OptionHandler) {
+            ((OptionHandler) instance).activateOptions();
+          }
+
+          return;
+      } else {
+          throw new PropertySetterException(
+                  "Conversion to type [" + paramTypes[0] + "] failed.");
+      }
     }
 
     getLogger().debug("Setting property [{}] to [{}].", name, arg);

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

Reply via email to