The promised patches are included as attachments.

Please also note the page http://qos.ch/containers/sc.html moved to http://qos.ch/logging/sc.html


At 16:08 15.02.2003 +0100, you wrote:

Hi Jake,

Nothing prevents you from instantiating a ContextClassLoaderSelector instance in InitContextListener. I'll supply the patch in the next few minutes.

At 11:03 14.02.2003 -0600, you wrote:
Hello Ceki,

No, I haven't as of yet.  I'll try that this weekend.

BTW, before you mentioned that doIdempotentInitialization() should be
moved from the ContextClassLoaderSelector to whatever code that is
performing initializatiion, such as the InitContextListener.  However,
I don't see how this is possible given the contents of the
initialization method...

    public static void doIdempotentInitialization() {
        if (!initialized) {
            try {
                Object guard = new Object();
                LogManager.setRepositorySelector(SINGLETON, guard);
                initialized = true;
            } catch (IllegalArgumentException iae) {
                // either ignore the exception or log the fact that the
                // setting of this custom repository selector failed because
                // another had been set previously and maybe we should set
                // "initialized" to "true" in here so this exception doesn't
                // occur again in this class
            }
        }
    }

Note the "SINGLETON" variable sent into setRepositorySelector.  This
is a private variable that is the singleton instance of the
ContextClassLoader...

    /**
     * singleton instance for this class
     */
    private static final ContextClassLoaderSelector SINGLETON =
        new ContextClassLoaderSelector();

--
Ceki 
Index: InitContextListener.java
===================================================================
RCS file: 
/home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/servlet/InitContextListener.java,v
retrieving revision 1.1
diff -u -u -r1.1 InitContextListener.java
--- InitContextListener.java    4 Feb 2003 06:28:16 -0000       1.1
+++ InitContextListener.java    15 Feb 2003 15:28:48 -0000
@@ -19,6 +19,7 @@
 import org.apache.log4j.helpers.LogLog;
 import org.apache.log4j.PropertyConfigurator;
 import org.apache.log4j.xml.DOMConfigurator;
+import org.apache.log4j.LogManager;
 
 import org.apache.log4j.selector.ContextClassLoaderSelector;
 
@@ -153,6 +154,8 @@
     // store the time at which the current application became fully initialized
     public static long applicationInitialized = 0L;
 
+    private static boolean selectorSet = false;
+
     private final static String PARAM_LOG4J_CONFIG_PATH = "log4j-config";
     private final static String PARAM_LOG4J_WATCH_INTERVAL = "log4j-cron";
     private final static String PARAM_LOG4J_LOG_HOME = "log4j-log-home";
@@ -167,7 +170,7 @@
 
         ServletContext context = sce.getServletContext();
 
-        initializeLog4j(context);
+       initializeLog4j(context);
     }
 
     /**
@@ -236,7 +239,7 @@
                             }
                             catch (NumberFormatException nfe) {}
                         }
-                        initLoggerRepository();
+                        setSelector();
                         context.log("Configuring Log4j from File: 
"+contextPath+systemConfigPath);
                         if (timerIntervalVal > 0) {
                             context.log("Configuring Log4j with watch interval: 
"+timerIntervalVal+"ms");
@@ -274,7 +277,7 @@
                     }
                     catch (MalformedURLException murle) {}
                     if (log4jURL!=null) {
-                        initLoggerRepository();
+                        setSelector();
                         context.log("Configuring Log4j from URL at path: 
/"+configPath);
                         if (isXMLConfigFile) {
                             try {
@@ -334,7 +337,20 @@
         }
     }
 
-    private void initLoggerRepository() {
-        ContextClassLoaderSelector.doIdempotentInitialization();
+  public static void setSelector() {
+    if (!selectorSet) {
+      try {
+       Object guard = new Object();
+       ContextClassLoaderSelector crs = new ContextClassLoaderSelector();
+       LogManager.setRepositorySelector(crs, guard);
+       selectorSet = true;
+      } catch (IllegalArgumentException iae) {
+       // either ignore the exception or log the fact that the
+       // setting of this custom repository selector failed because
+       // another had been set previously and maybe we should set
+       // "initialized" to "true" in here so this exception doesn't
+       // occur again in this class
+      }
     }
+  }
 }
Index: InitServlet.java
===================================================================
RCS file: 
/home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/servlet/InitServlet.java,v
retrieving revision 1.1
diff -u -u -r1.1 InitServlet.java
--- InitServlet.java    4 Feb 2003 06:28:16 -0000       1.1
+++ InitServlet.java    15 Feb 2003 15:28:49 -0000
@@ -22,6 +22,7 @@
 
 import org.apache.log4j.helpers.LogLog;
 import org.apache.log4j.PropertyConfigurator;
+import org.apache.log4j.LogManager;
 import org.apache.log4j.xml.DOMConfigurator;
 
 import org.apache.log4j.selector.ContextClassLoaderSelector;
@@ -77,6 +78,8 @@
 
     private static Boolean CONFIGURED = Boolean.FALSE;
 
+    private  boolean selectorSet = false;
+
     public void init() throws ServletException {
         if (CONFIGURED.equals(Boolean.FALSE)) {
             String configPath = getInitParameter(PARAM_LOG4J_CONFIG_PATH);
@@ -228,7 +231,15 @@
     }
 
     private void initLoggerRepository() {
-        ContextClassLoaderSelector.doIdempotentInitialization();
+      if (!selectorSet) {
+       try {
+         Object guard = new Object();
+         ContextClassLoaderSelector crs = new ContextClassLoaderSelector();
+         LogManager.setRepositorySelector(crs, guard);
+         selectorSet = true;
+       } catch (IllegalArgumentException iae) {
+       }
+      }
     }
 
     /**
Index: ContextClassLoaderSelector.java
===================================================================
RCS file: 
/home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/selector/ContextClassLoaderSelector.java,v
retrieving revision 1.2
diff -u -u -r1.2 ContextClassLoaderSelector.java
--- ContextClassLoaderSelector.java     14 Feb 2003 05:58:56 -0000      1.2
+++ ContextClassLoaderSelector.java     15 Feb 2003 15:28:08 -0000
@@ -58,22 +58,7 @@
     private static final Map HIER_MAP =
         Collections.synchronizedMap(new WeakHashMap());
 
-    /**
-     * singleton instance for this class
-     */
-    private static final ContextClassLoaderSelector SINGLETON =
-        new ContextClassLoaderSelector();
-
-    /**
-     * remember idempotent initialization status
-     */
-    private static boolean initialized = false;
-
-    /**
-     * private no-args constructor to guarantee no outside code can create an
-     * instance
-     */
-    private ContextClassLoaderSelector() {
+    public ContextClassLoaderSelector() {
     }
 
     /**
@@ -93,24 +78,4 @@
         return hierarchy;
     }
 
-    /**
-     * The Container should initialize the logger repository for each
-     * webapp upon startup or reload.  In this case, it is controllable
-     * via each webapp.
-     */
-    public static void doIdempotentInitialization() {
-        if (!initialized) {
-            try {
-                Object guard = new Object();
-                LogManager.setRepositorySelector(SINGLETON, guard);
-                initialized = true;
-            } catch (IllegalArgumentException iae) {
-                // either ignore the exception or log the fact that the
-                // setting of this custom repository selector failed because
-                // another had been set previously and maybe we should set
-                // "initialized" to "true" in here so this exception doesn't
-                // occur again in this class
-            }
-        }
-    }
 }

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

Reply via email to