tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r898468 - in /tomcat/trunk/java/org/apache/juli: ClassLoaderLogManager.java logging/LogFactory.java
Date Tue, 12 Jan 2010 19:06:49 GMT
Author: markt
Date: Tue Jan 12 19:06:48 2010
New Revision: 898468

URL: http://svn.apache.org/viewvc?rev=898468&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48421
Clean up a web application's logs and handlers when it stops. This involved modifying the
fix that prevented log messages being lost in shutdown.

Modified:
    tomcat/trunk/java/org/apache/juli/ClassLoaderLogManager.java
    tomcat/trunk/java/org/apache/juli/logging/LogFactory.java

Modified: tomcat/trunk/java/org/apache/juli/ClassLoaderLogManager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/juli/ClassLoaderLogManager.java?rev=898468&r1=898467&r2=898468&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/juli/ClassLoaderLogManager.java (original)
+++ tomcat/trunk/java/org/apache/juli/ClassLoaderLogManager.java Tue Jan 12 19:06:48 2010
@@ -46,6 +46,46 @@
  */
 public class ClassLoaderLogManager extends LogManager {
 
+    private final class Cleaner extends Thread {
+        
+        @Override
+        public void run() {
+            // The JVM us being shutdown. Make sure all loggers for all class
+            // loaders are shutdown
+            for (ClassLoaderLogInfo clLogInfo : classLoaderLoggers.values()) {
+                for (Logger logger : clLogInfo.loggers.values()) {
+                    resetLogger(logger);
+                }
+            }
+        }
+            
+        private void resetLogger(Logger logger) {
+            
+            Handler[] handlers = logger.getHandlers();
+            for (Handler handler : handlers) {
+                logger.removeHandler(handler);
+                try {
+                    handler.close();
+                } catch (Exception e) {
+                    // Ignore
+                }
+            }
+        }
+
+    }
+
+    
+    // ------------------------------------------------------------Constructors
+
+    public ClassLoaderLogManager() {
+        super();
+        try { 
+            Runtime.getRuntime().addShutdownHook(new Cleaner());
+        } catch (IllegalStateException ise) {
+            // We are probably already being shutdown. Ignore this error.
+        }
+    }
+
 
     // -------------------------------------------------------------- Variables
 
@@ -485,33 +525,6 @@
     }
     
 
-    /**
-     * Need to override reset so the loggers loaded by the web applications can
-     * be shutdown.
-     */
-    @Override
-    public void reset() {
-        super.reset();
-        for (ClassLoaderLogInfo classLoaderLogInfo : classLoaderLoggers.values()) {
-            for (Logger logger : classLoaderLogInfo.loggers.values()) {
-                resetLogger(logger);
-            }
-        }
-    }
-    
-    private void resetLogger(Logger logger) {
-        
-        Handler[] handlers = logger.getHandlers();
-        for (Handler handler : handlers) {
-            logger.removeHandler(handler);
-            try {
-                handler.close();
-            } catch (Exception e) {
-                // Ignore
-            }
-        }
-    }
-
     // ---------------------------------------------------- LogNode Inner Class
 
 

Modified: tomcat/trunk/java/org/apache/juli/logging/LogFactory.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/juli/logging/LogFactory.java?rev=898468&r1=898467&r2=898468&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/juli/logging/LogFactory.java (original)
+++ tomcat/trunk/java/org/apache/juli/logging/LogFactory.java Tue Jan 12 19:06:48 2010
@@ -19,6 +19,7 @@
 
 
 import java.util.Properties;
+import java.util.logging.LogManager;
 
 
 
@@ -325,8 +326,10 @@
      *
      * @param classLoader ClassLoader for which to release the LogFactory
      */
-    public static void release(ClassLoader classLoader) {
-        // nothing - we don't use any class loaders
+    public static void release(
+            @SuppressWarnings("unused") ClassLoader classLoader) {
+        // JULI's log manager looks at the current classLoader
+        LogManager.getLogManager().reset();
     }
 
 



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


Mime
View raw message