logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1469065 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java src/changes/changes.xml
Date Wed, 17 Apr 2013 20:41:23 GMT
Author: rgoers
Date: Wed Apr 17 20:41:23 2013
New Revision: 1469065

URL: http://svn.apache.org/r1469065
Log:
LOG4J2-213 - Calling the stop method on the LoggerContext during shutdown

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
    logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java?rev=1469065&r1=1469064&r2=1469065&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
Wed Apr 17 20:41:23 2013
@@ -59,6 +59,8 @@ public class LoggerContext implements or
 
     private final URI configLocation;
 
+    private ShutdownThread shutdownThread = null;
+
     /**
      * Status of the LoggerContext.
      */
@@ -137,6 +139,13 @@ public class LoggerContext implements or
                 if (status == Status.INITIALIZED) {
                     status = Status.STARTING;
                     reconfigure();
+                    shutdownThread = new ShutdownThread(this);
+                    try {
+                        Runtime.getRuntime().addShutdownHook(shutdownThread);
+                    } catch (SecurityException se) {
+                        LOGGER.warn("Unable to register shutdown hook due to security restrictions");
+                        shutdownThread = null;
+                    }
                     status = Status.STARTED;
                 }
             } finally {
@@ -149,6 +158,10 @@ public class LoggerContext implements or
         configLock.lock();
         try {
             status = Status.STOPPING;
+            if (shutdownThread != null) {
+                Runtime.getRuntime().removeShutdownHook(shutdownThread);
+                shutdownThread = null;
+            }
             updateLoggers(new NullConfiguration());
             config.stop();
             externalContext = null;
@@ -331,4 +344,18 @@ public class LoggerContext implements or
         return new Logger(ctx, name, messageFactory);
     }
 
+    private class ShutdownThread extends Thread {
+
+        private final LoggerContext context;
+
+        public ShutdownThread(LoggerContext context) {
+            this.context = context;
+        }
+
+        public void run() {
+            context.shutdownThread = null;
+            context.stop();
+        }
+    }
+
 }

Modified: logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java?rev=1469065&r1=1469064&r2=1469065&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java
(original)
+++ logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumePersistentManager.java
Wed Apr 17 20:41:23 2013
@@ -162,6 +162,7 @@ public class FlumePersistentManager exte
 
     @Override
     protected void releaseSub() {
+        LOGGER.debug("Shutting down FlumePersistentManager");
         worker.shutdown();
         try {
             worker.join();
@@ -315,9 +316,11 @@ public class FlumePersistentManager exte
             this.queue = queue;
             this.batchSize = batchsize;
             this.secretKey = secretKey;
+            this.setDaemon(true);
         }
 
         public void shutdown() {
+            LOGGER.debug("Writer thread shutting down");
             this.shutdown = true;
             if (queue.size() == 0) {
                 queue.add(SHUTDOWN.getBytes(UTF8));

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1469065&r1=1469064&r2=1469065&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Wed Apr 17 20:41:23 2013
@@ -23,6 +23,9 @@
 
   <body>
     <release version="2.0-beta5" date="@TBD@" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-212" dev="rgoers" type="fix">
+        Call LoggerContext.stop when the application is shutdown.
+      </action>
       <action issue="LOG4J2-210" dev="rgoers" type="fix" due-to="Arkin Yetis">
         MapMessage was not enclosing key value in quotes when generating XML.
       </action>



Mime
View raw message