logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ceki Gülcü <...@qos.ch>
Subject Re: PATCH: modify config file loading to allow custom URL types
Date Wed, 11 Jul 2001 05:11:48 GMT
At 18:23 10.07.2001 -0400, Colin Sampaleanu wrote:
>There is actually another problem with your version of the code. It is fine
>with a url like
>
>zip:a/path/to/an/archive.war#WEB-INF/log4j.properties
>
>This is pretty typical of what you would actually get back from the WebLogic
>classloader when telling it to find log4j.properties from the classpath, for
>a .WAR file deployed into it.
>
>On the other hand, it would get confused with a URL with a period in the
>filename, but not path. In this case it would think that was a classname.
>
>zip:a/path/to/an/archive.zip#log4j.properties
>
>My original code least handled this case when getting back a URL from the
>classloader, since in that case it would never even look at the ref as
>something special. Obviously there would still be an issue when the url came
>from somewhere else, like an environment variable.
>
>I am of mixed feelings about this whole scheme of piggybacking a
>configurator classname as a ref portion of a URL. Obviously there are cases
>when you can't in fact tell if it is a classname or a valid part of a custom
>url... I would have just used a separate system variable myself to indicate
>a special configurator class...

Yes, I must agree. A separate variable seems like the way to go. How about
keeping "log4j.configuration" without piggybacking a
configurator classname and adding a separate variable "log4j.configuratorClass" instead?

Regards, Ceki



>----- Original Message -----
>From: "Colin Sampaleanu" <colinml1@exis.com>
>To: "LOG4J Developers Mailing List" <log4j-dev@jakarta.apache.org>
>Sent: Tuesday, July 10, 2001 5:38 PM
>Subject: Re: PATCH: modify config file loading to allow custom URL types
>
>
>> Hi,
>>
>> Unfortunately I have to take back my comment about this code being ok. My
>> original patch worked both in and outside of WebLogic. I only tried your
>> patch inside WL (with a prop file in a .WAR archive, which forces the
>custom
>> URL to be used), where it worked fine. Unfortunately your code will get a
>> null pointer exception outside. You need to check the return value from
>> getRef() for a null, as my original code did...
>>
>> Regards,
>>
>> Colin
>>
>> ----- Original Message -----
>> From: "Ceki Gülcü" <cgu@qos.ch>
>> To: "LOG4J Developers Mailing List" <log4j-dev@jakarta.apache.org>
>> Sent: Thursday, July 05, 2001 12:54 PM
>> Subject: Re: PATCH: modify config file loading to allow custom URL types
>>
>>
>>
>> Colin,
>>
>> I modified OptionConverter.java as follows:
>>
>>   static
>>   public
>>   void selectAndConfigure(URL url, Hierarchy hierarchy) {
>>     String clazz = url.getRef();
>>
>>     if (clazz.indexOf('.') == -1 || clazz.indexOf('/') != -1 ||
>> clazz.indexOf('\\') != -1) {
>>       LogLog.warn("Suspicious reference part in URL ["+url+
>>                   "] will ignore refence part assuming BEA Weblogic
>> environment.");
>>       clazz = null;
>>     }
>>
>>
>>     Configurator configurator = null;
>>
>>     if(clazz != null) {
>>       LogLog.debug("Preferred configurator class: " + clazz);
>>     ....
>>
>>   }
>>
>> Category.java remains unchanged. Can you please double check that my
>> simplified patch works.
>> You can get the latest code from our CVS repository. Best regards, Ceki
>>
>> At 14:20 29.06.2001 +0000, you wrote:
>> >(same patch as before, but diffed using -u option...)
>> >
>> >>As per my previous email with Ceki, this patch modifies the
>configuration
>> file loading code so that while still allowing a 'ref' or anchor portion
>of
>> a URL to specify a class name for a custom configurator, it can also work
>> with custom URL schemes such as used in WebLogic to specify a file within
>an
>> archive, e.g.
>> >>zip:/part1/part2/whatever.war#WEB-INF/classes/log4j.properties
>> >>With the new code, for the ref portion of a URL to be considered a
>> classname, it must consist of at least one package element and one
>classname
>> element (e.g. mypackage.Myclass), and must not have the file separator
>> character in it. Also, when the URL comes from a classloader as opposed to
>a
>> system properly, the code will never consider the ref to be a classname,
>> since that wouldn't make sense (e.g. in this case the ref will always be
>> part of a custom URL).
>> >
>> >Index: Category.java
>> >===================================================================
>> >RCS file:
>> /home/cvspublic/jakarta-log4j/src/java/org/apache/log4j/Category.java,v
>> >retrieving revision 1.35
>> >diff -w -u -r1.35 Category.java
>> >--- Category.java       2001/06/26 19:40:05     1.35
>> >+++ Category.java       2001/06/29 14:12:44
>> >@@ -131,12 +131,16 @@
>> >
>> >DEFAULT_CONFIGURATION_KEY,
>> >
>> DEFAULT_CONFIGURATION_FILE);
>> >     URL url = null;
>> >+      boolean urlRefMayBeConfigurator = true;
>> >     try {
>> >-       // so, resource is not a URL:
>> >-       // attempt to get the resource from the class path
>> >        url = new URL(resource);
>> >     } catch (MalformedURLException ex) {
>> >+       // if resource is not a URL then
>> >+       // attempt to get the resource from the class path
>> >        url = Loader.getResource(resource, Category.class);
>> >+        // any ref portion in URL returned by classload is specific to
>> that URL,
>> >+        // not a Configurator class name
>> >+        urlRefMayBeConfigurator = false;
>> >     }
>> >
>> >     // If we have a non-null url, then delegate the rest of the
>> >@@ -144,7 +148,7 @@
>> >     // method.
>> >     if(url != null) {
>> >        LogLog.debug("Using URL ["+url+"] for automatic log4j
>> configuration.");
>> >-       OptionConverter.selectAndConfigure(url, defaultHierarchy);
>> >+       OptionConverter.selectAndConfigure(url, urlRefMayBeConfigurator,
>> defaultHierarchy);
>> >     } else {
>> >        LogLog.debug("Could not find resource: ["+resource+"].");
>> >     }
>> >Index: helpers/OptionConverter.java
>> >===================================================================
>> >RCS file:
>>
>/home/cvspublic/jakarta-log4j/src/java/org/apache/log4j/helpers/OptionConver
>> ter.java,v
>> >retrieving revision 1.17
>> >diff -w -u -r1.17 OptionConverter.java
>> >--- helpers/OptionConverter.java        2001/06/20 07:59:46     1.17
>> >+++ helpers/OptionConverter.java        2001/06/29 14:12:45
>> >@@ -399,9 +399,16 @@
>> > /**
>> >    Configure log4j given a URL.
>> >-     <p>The URL format is important. Its <em>reference</em>
part is
>> >-     taken as the class name of the configurator. For example, if you
>> >-     invoke your application using the command line
>> >+     <p>The URL format is important. If the
>> <em>urlRefMayBeConfigurator</em>
>> >+     param is true, then its <em>reference</em> part (if any) is
>> potentially
>> >+     considered to be the class name of the configurator. Since the ref
>> part
>> >+     may also be used by some custom URL types (e.g. to qualify a
>specific
>> file
>> >+     within another archive file), for the ref string to be considered a
>> class
>> >+     name, it must be a fully qualified class name including at least
>one
>> >+     package, and must not contain any file separator characters such as
>> '/' or
>> >+     '\' since those would never be part of a valid class name, and are
>a
>> strong
>> >+     indication of a custom URL type. For example, if you invoke your
>> >+     application using the command line
>> >    <pre>
>>
>java -Dlog4j.configuration=file:/temp/myconfig.xyz#com.myCompany.myConfigura
>> tor
>> >    </pre>
>> >@@ -412,8 +419,8 @@
>> >    configurator you specify <em>must</em> implement the {@link
>> >    Configurator} interface.
>> >-     <p>If the URL has no reference part, then the {@link
>> >-     PropertyConfigurator} will parse the URL. However, if the URL
>> >+     <p>If no configurator is specified via a URL reference part, then
>the
>> >+     {@link PropertyConfigurator} will parse the URL. However, if the
>URL
>> >    ends with a ".xml" extension, then the {@link DOMConfigurator}
>> >    will be used to parse the URL.
>> >@@ -425,12 +432,29 @@
>> >    @since 1.0 */
>> > static
>> > public
>> >-  void selectAndConfigure(URL url, Hierarchy hierarchy) {
>> >-    String clazz = url.getRef();
>> >+  void selectAndConfigure(URL url, boolean urlRefMayBeConfigurator,
>> >+                          Hierarchy hierarchy) {
>> >+
>> >+    // assume a 'ref' portion of a URL may be Configurator class
>> >+    String clazz = null;
>> >+    if (urlRefMayBeConfigurator) {
>> >+      clazz = url.getRef();
>> >+      if (clazz != null) {
>> >+        String fileSep = "/";
>> >+        try { fileSep = System.getProperty("file.separator"); }
>> catch(Exception e) {}
>> >+        // it's only a class name if it has a period somewhere in it,
>and
>> it's
>> >+        // not a class name if it has a file separator (explicitly check
>> both
>> >+        // unix and windows versions since Java itself will always allow
>> them
>> >+        // regardless of actual platform)
>> >+        if (clazz.indexOf('.') == -1 || clazz.indexOf(fileSep) != -1 ||
>> >+            clazz.indexOf('/') != -1 || clazz.indexOf('\\') != -1)
>> >+          clazz = null;
>> >+      }
>> >+    }
>> >   Configurator configurator = null;
>> >-    if(clazz != null) {
>> >+    if (clazz != null && clazz.length() > 0) {
>> >     LogLog.debug("Preferred configurator class: " + clazz);
>> >     configurator = (Configurator) instantiateByClassName(clazz,
>> >
>> Configurator.class,
>> >@@ -440,6 +464,11 @@
>> >        return;
>> >     }
>> >   } else {
>> >+      // hmm, this test is actually no longer valid if we have a custom
>> URL type
>> >+      // such as:
>> >+      // 'zip:/a/b/c/d.war#e/f/log4j.properties'
>> >+      // which is what a custom classloader like WebLogic's may return
>as
>> a URL
>> >+      // reference to a file inside of an archive
>> >     String filename = url.getFile();
>> >     if(filename != null && filename.endsWith(".xml")) {
>> >        try {
>> >@@ -455,4 +484,16 @@
>> >   configurator.doConfigure(url, hierarchy);
>> > }
>> >+
>> >+
>> >+  /**
>> >+     Configure log4j given a URL.
>> >+     This method signature maintained for compatibility
>> >+   */
>> >+  static
>> >+  public
>> >+  void selectAndConfigure(URL url, Hierarchy hierarchy) {
>> >+    selectAndConfigure(url, true, hierarchy);
>> >+  }
>> >+
>> >}
>> >---------------------------------------------------------------------
>> >To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
>> >For additional commands, e-mail: log4j-dev-help@jakarta.apache.org
>> >
>>
>> --
>> Ceki Gülcü
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: log4j-dev-help@jakarta.apache.org
>>
>>
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-dev-help@jakarta.apache.org

--
Ceki Gülcü


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org


Mime
View raw message