Hello,

I know that PropertyConfigurator support placeholders
and will resolve them using System properties or properties in the
configuration file
being parsed.

But what if I would like to supply properties (for the placeholders)
at runtime ?

suppose I have this in my config file:
log4j.appender.RollingFile.File = /var/log/${webapp.name}.log
and I want to set the value for the placeholder in a ServletContextListener.

option (a)
String webappName = servletContext.getServletContextName();
System.setProperty("webapp.name", webappName);
PropertyConfigurator.configure(url);

=> possible race condition since in Tomcat the system properties are
shared by all webapps (unfortunately)

option (b):
           File configFile = ...
           Properties properties = new Properties();
           properties.load(new FileInputStream(configFile));
           properties.setProperty("webapp.name", webappName);
           PropertyConfigurator.configure(properties);

=> haven't tried this yet but I guess it would work.

option (c)
add these methods to PropertyConfigurator:

public static void configure(URL configURL, Properties placeholders);
public static void configure(String configFilename), Properties placeholders);

What do you think ?

Maarten

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

Reply via email to