Bug 14350 - Patch to substitute variables in the log4j.configuration property
Summary: Patch to substitute variables in the log4j.configuration property
Status: RESOLVED WONTFIX
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.3alpha
Hardware: All All
: P3 enhancement
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords:
: 25107 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-11-07 13:56 UTC by Ceki Gulcu
Modified: 2007-08-22 14:24 UTC (History)
2 users (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ceki Gulcu 2002-11-07 13:56:59 UTC
Submitted by: Michael Locher <locher@iam.unibe.ch> 

Hi all


I had to find a way to provide a user dependent configuration file for my java 
webstart application. the stright forward way to do so, is to handle property 
substitution in the LogManager initalisation.


webstart users can provide something like this:


<property name="log4j.configuration" value="file://
${user.home}/log4j.properties" />


the substitiution code was already there, so the patch is quite small.
one new method in OptionConverter and 3 renamings in LogManager.


In what format do you expect the patch? I have included a diff against CVS HEAD 
below.


Regards
  Michael Locher



#####################################################################


diff -r1.37 OptionConverter.java
20a21
> //                 Michael Locher (locher@iam.unibe.ch)
98a100,120
>   /**
>      Very similar to <code>System.getProperty</code> except
>      that the {@link SecurityException} is hidden and substitutions are perfor
med.
>
>      @param key The key to search for.
>      @param def The default value to return.
>      @return the string value of the system property with applied substitution
s, or the default
>      value if there is no property with that key.
>   */
>   public
>   static
>   String getSubstitutedSystemProperty(String key, String def) {
>       try {
>         Properties systemProperties =  System.getProperties();
>         return OptionConverter.substVars(OptionConverter.getSystemProperty(key
, def),
>                                          System.getProperties());
>       } catch(Throwable e) { // MS-Java throws com.ms.security.SecurityExcepti
onEx
>         LogLog.debug("Was not allowed to read system properties.");
>         return def;
>       }
>   }


#####################################################################


diff -r1.9 LogManager.java
78,79c78,79
<     String override =OptionConverter.getSystemProperty(DEFAULT_INIT_OVERRIDE_K
EY,
<                                                      null);
---
>     String override =OptionConverter.getSubstitutedSystemProperty(DEFAULT_INIT
_OVERRIDE_KEY,
>                                                                 null);
85c85
<       String configurationOptionStr = OptionConverter.getSystemProperty(
---
>       String configurationOptionStr = OptionConverter.getSubstitutedSystemProp
erty(
89c89
<       String configuratorClassName = OptionConverter.getSystemProperty(
---
>       String configuratorClassName = OptionConverter.getSubstitutedSystemPrope
rty(


#####################################################################
Comment 1 Curt Arnold 2007-08-22 09:38:55 UTC
I can see the value of it and don't see another way to perform the substitution in Webstart, however I'm 
uncomfortable making the change this late in log4j 1.2's life.  I'd recommend specifying 
log4j.configuratorClass and providing a class that evaluates user.home to before delegating to one of the 
other configurators.
Comment 2 Curt Arnold 2007-08-22 14:24:38 UTC
*** Bug 25107 has been marked as a duplicate of this bug. ***