ASF Bugzilla – Attachment 20974 Details for
Bug 43619
Simple proposal for pluggable sys-props resolvers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Proposed patch - 'skeletal' version
patch-3.patch (text/plain), 5.58 KB, created by
Lilianne E. Blaze
on 2007-10-13 22:52:22 UTC
(
hide
)
Description:
Proposed patch - 'skeletal' version
Filename:
MIME Type:
Creator:
Lilianne E. Blaze
Created:
2007-10-13 22:52:22 UTC
Size:
5.58 KB
patch
obsolete
># This patch file was generated by NetBeans IDE ># Following Index: paths are relative to: D:\Work\Java\Open_Source\custom-log4j\src\main\java ># This patch can be applied using context Tools: Patch action on respective folder. ># It uses platform neutral UTF-8 encoding and \n newlines. ># Above lines and this line are ignored by the patching process. >Index: org/apache/log4j/helpers/OptionConverter.java >--- org/apache/log4j/helpers/OptionConverter.java Base (BASE) >+++ org/apache/log4j/helpers/OptionConverter.java Locally Modified (Based On LOCAL) >@@ -25,6 +25,7 @@ > import org.apache.log4j.PropertyConfigurator; > > // Contributors: Avy Sharell (sharell@online.fr) >+import org.apache.log4j.sysprops.PropertyResolver; > // Matthieu Verbert (mve@zurich.ibm.com) > // Colin Sampaleanu > >@@ -401,13 +402,9 @@ > } else { > j += DELIM_START_LEN; > String key = val.substring(j, k); >- // first try in System properties >- String replacement = getSystemProperty(key, null); >- // then try props parameter >- if(replacement == null && props != null) { >- replacement = props.getProperty(key); >- } > >+ String replacement = PropertyResolver.getInstance().resolveProperty(key, props); >+ > if(replacement != null) { > // Do variable substitution on the replacement string > // such that we can solve "Hello ${x2}" as "Hello p1" >Index: org/apache/log4j/sysprops/DefaultPropertyResolver.java >--- org/apache/log4j/sysprops/DefaultPropertyResolver.java Locally New >+++ org/apache/log4j/sysprops/DefaultPropertyResolver.java Locally New >@@ -0,0 +1,38 @@ >+ >+package org.apache.log4j.sysprops; >+ >+import java.util.Properties; >+import org.apache.log4j.helpers.OptionConverter; >+ >+/** >+ * Implements default behaviour: 1st check system properties, 2nd check given >+ * properties. >+ * @author LBlaze >+ */ >+public class DefaultPropertyResolver extends PropertyResolver >+{ >+ >+ /** >+ * >+ */ >+ public String resolveProperty(String key, Properties localProps, String def) >+ { >+ String systemTry = OptionConverter.getSystemProperty(key, null); >+ if( systemTry != null ) >+ { >+ return systemTry; >+ } >+ >+ if( localProps != null ) >+ { >+ String localTry = localProps.getProperty(key); >+ if( localTry != null ) >+ { >+ return localTry; >+ } >+ } >+ >+ return def; >+ } >+ >+} >\ No newline at end of file >Index: org/apache/log4j/sysprops/Jndi1stSystem2ndPropertyResolver.java >--- org/apache/log4j/sysprops/Jndi1stSystem2ndPropertyResolver.java Locally New >+++ org/apache/log4j/sysprops/Jndi1stSystem2ndPropertyResolver.java Locally New >@@ -0,0 +1,62 @@ >+ >+package org.apache.log4j.sysprops; >+ >+import java.util.Properties; >+import javax.naming.Context; >+import javax.naming.InitialContext; >+import org.apache.log4j.helpers.OptionConverter; >+ >+/** >+ * >+ * @author LBlaze >+ */ >+public class Jndi1stSystem2ndPropertyResolver >+extends PropertyResolver >+{ >+ >+ public String resolveProperty(String key, Properties localProps, String def) >+ { >+ String jndiTry = resolveJndiProperty(key); >+ if( jndiTry != null ) >+ { >+ return jndiTry; >+ } >+ >+ String systemTry = OptionConverter.getSystemProperty(key, null); >+ if( systemTry != null ) >+ { >+ return systemTry; >+ } >+ >+ if( localProps != null ) >+ { >+ String localTry = localProps.getProperty(key); >+ if( localTry != null ) >+ { >+ return localTry; >+ } >+ } >+ >+ return def; >+ } >+ >+ >+ protected String resolveJndiProperty(String key) >+ { >+ try >+ { >+ Context initCtx = new InitialContext(); >+ Context envCtx = (Context) initCtx.lookup("java:comp/env"); >+ String value = (String)envCtx.lookup("log4j/" + key); >+ return value; >+ } >+ catch(Exception e) >+ { >+ e.printStackTrace(); >+ return null; >+ } >+ } >+ >+ >+ >+} >Index: org/apache/log4j/sysprops/PropertyResolver.java >--- org/apache/log4j/sysprops/PropertyResolver.java Locally New >+++ org/apache/log4j/sysprops/PropertyResolver.java Locally New >@@ -0,0 +1,50 @@ >+ >+package org.apache.log4j.sysprops; >+ >+import java.util.Properties; >+import org.apache.log4j.helpers.LogLog; >+ >+/** >+ * >+ * @author LBlaze >+ */ >+public abstract class PropertyResolver >+{ >+ >+ private static PropertyResolver instance = null; >+ >+ public static PropertyResolver getInstance() >+ { >+ if (instance == null) { >+ instance = createInstance(); >+ } >+ return instance; >+ } >+ >+ protected static PropertyResolver createInstance() >+ { >+ String log4jPropertyResolver = ""; >+ try { >+ log4jPropertyResolver = System.getProperty("log4j.propertyResolver", null); >+ if (log4jPropertyResolver != null && !log4jPropertyResolver.equals("")) { >+ Object o = Class.forName(log4jPropertyResolver).newInstance(); >+ if (o instanceof PropertyResolver) { >+ LogLog.debug("Using PropertyResolver " + log4jPropertyResolver); >+ return (PropertyResolver) o; >+ } >+ } else { >+ LogLog.debug("Using default PropertyResolver"); >+ } >+ } catch (Exception e) { >+ LogLog.error("Problem instantiating PropertyResolver " + log4jPropertyResolver, e); >+ } >+ return new DefaultPropertyResolver(); >+ } >+ >+ public String resolveProperty(String key, Properties localProps) >+ { >+ return resolveProperty(key, localProps, null); >+ } >+ >+ public abstract String resolveProperty(String key, Properties localProps, String def); >+} >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 43619
: 20974