logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1386485 - /logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/AsynchAppender.java
Date Mon, 17 Sep 2012 06:25:38 GMT
Author: rgoers
Date: Mon Sep 17 06:25:38 2012
New Revision: 1386485

URL: http://svn.apache.org/viewvc?rev=1386485&view=rev
Log:
Improve error handling

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/AsynchAppender.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/AsynchAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/AsynchAppender.java?rev=1386485&r1=1386484&r2=1386485&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/AsynchAppender.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/AsynchAppender.java
Mon Sep 17 06:25:38 2012
@@ -54,6 +54,7 @@ public final class AsynchAppender extend
     private AsynchThread thread = null;
 
     private static final int DEFAULT_QUEUE_SIZE = 128;
+    private static final String SHUTDOWN = "Shutdown";
 
     private AsynchAppender(String name, Filter filter, AppenderRef[] appenderRefs, String
errorRef,
                            int queueSize, boolean blocking,
@@ -183,13 +184,33 @@ public final class AsynchAppender extend
 
         public void run() {
             while (!shutdown) {
+                Serializable s;
                 try {
-                    Log4jLogEvent event = Log4jLogEvent.deserialize(queue.take());
-                    for (AppenderControl control : appenders) {
-                        control.callAppender(event);
+                    s = queue.take();
+                    if (s != null && s instanceof String && SHUTDOWN.equals(s.toString()))
{
+                        shutdown = true;
+                        continue;
                     }
                 } catch (InterruptedException ex) {
-                    // May have been interrupted to shut down.
+                    // No good reason for this.
+                    continue;
+                }
+                Log4jLogEvent event = Log4jLogEvent.deserialize(s);
+                boolean success = false;
+                for (AppenderControl control : appenders) {
+                    try {
+                        control.callAppender(event);
+                        success = true;
+                    } catch (Exception ex) {
+                        // If no appender is successful the error appender will get it.
+                    }
+                }
+                if (!success && errorAppender != null) {
+                    try {
+                        errorAppender.callAppender(event);
+                    } catch (Exception ex) {
+                        // Silently accept the error.
+                    }
                 }
             }
             // Process any remaining items in the queue.
@@ -207,7 +228,9 @@ public final class AsynchAppender extend
 
         public void shutdown() {
             shutdown = true;
-            this.interrupt();
+            if (queue.isEmpty()) {
+                queue.offer(SHUTDOWN);
+            }
         }
     }
 }



Mime
View raw message