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



##########
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() {

Review comment:
       Why not simply extending from `AutoCloseable` and overriding its 
`close()`? I guess, there have been a discussion about this in the mailing 
list, though it is good to communicate the context here as well.

##########
File path: 
log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
##########
@@ -405,6 +405,7 @@ public boolean stop(final long timeout, final TimeUnit 
timeUnit) {
             }
         }
         LOGGER.debug("Stopped LoggerContext[name={}, {}] with status {}", 
getName(), this, true);
+       StatusLogger.getLogger().prepareToStop();

Review comment:
       Again, I think I am missing some context here. Would you mind 
elaborating a bit on the necessity of this line here, please?

##########
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:
       I am still reading through the sources... Though I am confused by this 
step: Why do we have to have a system stream listener?

##########
File path: 
log4j-kafka/src/test/java/org/apache/logging/log4j/kafka/builder/ConfigurationBuilderTest.java
##########
@@ -106,14 +112,27 @@ private void addTestFixtures(final String name, final 
ConfigurationBuilder<Built
                 INDENT + "</Loggers>" + EOL +
             "</Configuration>" + EOL;
 
-    // TODO make test run properly on Windows
     @Test
     public void testXmlConstructing() throws Exception {
         //assumeTrue(System.lineSeparator().length() == 1); // Only run test 
on platforms with single character line endings (such as Linux), not on Windows

Review comment:
       I guess we can remove this as well.

##########
File path: src/changes/changes.xml
##########
@@ -31,6 +31,19 @@
          - "remove" - Removed
     -->
     <release version="3.0.0" date="2021-MM-DD" description="GA Release 3.0.0">
+      <action issue="LOG4J2-3024" dev="mattsicker" type="fix" due-to="Tim 
Perry">
+        Cleanly shutdown status logger when log4j is stopping to ensure file 
handles
+        are promptly released to avoid resource leakage.
+      </action>

Review comment:
       Would you mind including only your changes, please? (Is Matt, @jvz, 
really responsible for this change?)




-- 
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