perry2of5 commented on a change in pull request #469:
URL: https://github.com/apache/logging-log4j2/pull/469#discussion_r622409154



##########
File path: 
log4j-api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
##########
@@ -205,6 +205,32 @@ public void reset() {
             clear();
         }
     }
+    
+    /**
+     * Stop all the listeners except those writing to standard out or error. If
+     * no loggers write to standard out or error, then add one and stop the 
+     * others.
+     */
+    public void prepareToStop() {
+        final Collection<StatusListener> listenersToClose = new 
ArrayList<>(listeners.size());
+        boolean hasSystemStreamWriter = false;
+        for (final StatusListener listener : listeners) {
+               if (listener instanceof StatusConsoleListener) {
+                       if (((StatusConsoleListener) 
listener).writesToSystemStream()) {
+                               hasSystemStreamWriter = true;
+                       } else {
+                               listenersToClose.add(listener);
+                               
+                       }
+               }
+        }
+        if (!hasSystemStreamWriter) {
+               registerListener(new StatusConsoleListener(getLevel()));
+        }

Review comment:
       In the dev email list, on Feb 23, "What is going on with Master?" thread:
   
   I said:
   
   My thought is we choose one of two options:
   
   Option A:
   1) check if any StatusLogger is writing to standard out or standard error. 
If not, add one.
   2) stop any loggers that don't write to standard out or standard error.
   
   Option B:
   1) stop any loggers that don't write to standard out or standard error.
   
   Option A could cause the log messages to be split across two destinations, 
but they all get sent somewhere. Option B could lose shutdown messages when 
writing to a file, but by that point it may not matter.
   
   
   Ralph replied:
   
   I would suggest that if it is writing to something other than System.out 
that it be redirected back there and then the OutputStream be closed. However, 
I’ve not looked at the code recently so I am not sure what it takes to do that.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to