That's an intersting idea.  You can post an enhancement report in bugzilla along
with your implementation.  However, I'm not sure if this would be something that
would go into Log4j-1.2.xx because it is pretty much in bugfix mode.  New
development is on the trunk for the 1.3.xx releases.

The way I solved it was to create unique system properties based on the
application.  Instead of...

log4j.appender.RollingFile.File = /var/log/${webapp.name}.log

I do...

log4j.appender.RollingFile.File = /var/log/${mywebapp.log.home}.log

Where "mywebapp" is the specific name of the application I'm deploying.  I then
query for the name of the webapp at runtime so I can have generic code that
sets the system property for the current webapp.  This way, I don't stomp on
existing system properties because the system property name will be different
for each webapp, but named in a predictable way so you can reference it in your
config file.

You can see all this in the logging-log4j-sanbox...
http://svn.apache.org/viewvc/logging/sandbox/log4j/log4j_sandbox/trunk/src/java/org/apache/log4j/servlet/

Look specifically at:
InitContextListener.java
InitShutdownController.java


Jake

Quoting Maarten Bosteels <[EMAIL PROTECTED]>:

> 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]
>




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

Reply via email to