You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2022/06/18 18:20:34 UTC

[logging-log4j2] branch master updated (c02b699bba -> d1c265e714)

This is an automated email from the ASF dual-hosted git repository.

mattsicker pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


    from c02b699bba Cherry-pick the `ServiceLoaderUtil` changes from `release-2.x`
     new 4e96991351 Finish merge of LifeCycle2 into LifeCycle
     new d1c265e714 Only clean up files before tests

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../log4j/test/junit/AbstractFileCleaner.java      |  8 +-----
 .../org/apache/logging/log4j/core/LifeCycle2.java  | 27 -------------------
 .../log4j/web/Log4jServletContextListener.java     | 28 ++++++++------------
 .../Log4jShutdownOnContextDestroyedListener.java   | 26 ++++++++-----------
 .../log4j/web/Log4jServletContextListener.java     | 30 +++++++++-------------
 .../Log4jShutdownOnContextDestroyedListener.java   | 30 +++++++++-------------
 6 files changed, 46 insertions(+), 103 deletions(-)
 delete mode 100644 log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle2.java


[logging-log4j2] 01/02: Finish merge of LifeCycle2 into LifeCycle

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 4e96991351e98589687cc95739b67eb4d0ac9889
Author: Matt Sicker <ma...@apache.org>
AuthorDate: Sat Jun 18 12:48:25 2022 -0500

    Finish merge of LifeCycle2 into LifeCycle
    
    Signed-off-by: Matt Sicker <ma...@apache.org>
---
 .../org/apache/logging/log4j/core/LifeCycle2.java  | 27 -------------------
 .../log4j/web/Log4jServletContextListener.java     | 28 ++++++++------------
 .../Log4jShutdownOnContextDestroyedListener.java   | 26 ++++++++-----------
 .../log4j/web/Log4jServletContextListener.java     | 30 +++++++++-------------
 .../Log4jShutdownOnContextDestroyedListener.java   | 30 +++++++++-------------
 5 files changed, 45 insertions(+), 96 deletions(-)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle2.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle2.java
deleted file mode 100644
index 7287e8d8b1..0000000000
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/LifeCycle2.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core;
-
-/**
- * Extends the LifeCycle interface.
- * <p>
- *  This interface should be merged with the super-interface in 3.0.
- * </p>
- * @since 2.7
- */
-public interface LifeCycle2 extends LifeCycle {
-}
diff --git a/log4j-jakarta-web/src/main/java/org/apache/logging/log4j/web/Log4jServletContextListener.java b/log4j-jakarta-web/src/main/java/org/apache/logging/log4j/web/Log4jServletContextListener.java
index f0f5881b08..bf0d364f4e 100644
--- a/log4j-jakarta-web/src/main/java/org/apache/logging/log4j/web/Log4jServletContextListener.java
+++ b/log4j-jakarta-web/src/main/java/org/apache/logging/log4j/web/Log4jServletContextListener.java
@@ -16,18 +16,16 @@
  */
 package org.apache.logging.log4j.web;
 
-import java.util.Locale;
-import java.util.concurrent.TimeUnit;
-
 import jakarta.servlet.ServletContext;
 import jakarta.servlet.ServletContextEvent;
 import jakarta.servlet.ServletContextListener;
-
 import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LifeCycle2;
 import org.apache.logging.log4j.status.StatusLogger;
 import org.apache.logging.log4j.util.Strings;
 
+import java.util.Locale;
+import java.util.concurrent.TimeUnit;
+
 /**
  * In environments older than Servlet 3.0, this initializer is responsible for starting up Log4j logging before anything
  * else happens in application initialization. In all environments, this shuts down Log4j after the application shuts
@@ -50,7 +48,7 @@ public class Log4jServletContextListener implements ServletContextListener {
     public void contextInitialized(final ServletContextEvent event) {
         this.servletContext = event.getServletContext();
         LOGGER.debug("Log4jServletContextListener ensuring that Log4j starts up properly.");
-        
+
         if ("true".equalsIgnoreCase(servletContext.getInitParameter(
                 Log4jWebSupport.IS_LOG4J_AUTO_SHUTDOWN_DISABLED))) {
         	throw new IllegalStateException("Do not use " + getClass().getSimpleName() + " when "
@@ -78,16 +76,12 @@ public class Log4jServletContextListener implements ServletContextListener {
 
 		this.initializer.clearLoggerContext(); // the application is finished
 		// shutting down now
-		if (initializer instanceof LifeCycle2) {
-			final String stopTimeoutStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT);
-			final long stopTimeout = Strings.isEmpty(stopTimeoutStr) ? DEFAULT_STOP_TIMEOUT
-					: Long.parseLong(stopTimeoutStr);
-			final String timeoutTimeUnitStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT_TIMEUNIT);
-			final TimeUnit timeoutTimeUnit = Strings.isEmpty(timeoutTimeUnitStr) ? DEFAULT_STOP_TIMEOUT_TIMEUNIT
-					: TimeUnit.valueOf(timeoutTimeUnitStr.toUpperCase(Locale.ROOT));
-			((LifeCycle2) this.initializer).stop(stopTimeout, timeoutTimeUnit);
-		} else {
-			this.initializer.stop();
-		}
+        final String stopTimeoutStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT);
+        final long stopTimeout = Strings.isEmpty(stopTimeoutStr) ? DEFAULT_STOP_TIMEOUT
+                : Long.parseLong(stopTimeoutStr);
+        final String timeoutTimeUnitStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT_TIMEUNIT);
+        final TimeUnit timeoutTimeUnit = Strings.isEmpty(timeoutTimeUnitStr) ? DEFAULT_STOP_TIMEOUT_TIMEUNIT
+                : TimeUnit.valueOf(timeoutTimeUnitStr.toUpperCase(Locale.ROOT));
+        this.initializer.stop(stopTimeout, timeoutTimeUnit);
 	}
 }
diff --git a/log4j-jakarta-web/src/main/java/org/apache/logging/log4j/web/Log4jShutdownOnContextDestroyedListener.java b/log4j-jakarta-web/src/main/java/org/apache/logging/log4j/web/Log4jShutdownOnContextDestroyedListener.java
index 910670a66c..90bb027f9e 100644
--- a/log4j-jakarta-web/src/main/java/org/apache/logging/log4j/web/Log4jShutdownOnContextDestroyedListener.java
+++ b/log4j-jakarta-web/src/main/java/org/apache/logging/log4j/web/Log4jShutdownOnContextDestroyedListener.java
@@ -16,18 +16,16 @@
  */
 package org.apache.logging.log4j.web;
 
-import java.util.Locale;
-import java.util.concurrent.TimeUnit;
-
 import jakarta.servlet.ServletContext;
 import jakarta.servlet.ServletContextEvent;
 import jakarta.servlet.ServletContextListener;
-
 import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LifeCycle2;
 import org.apache.logging.log4j.status.StatusLogger;
 import org.apache.logging.log4j.util.Strings;
 
+import java.util.Locale;
+import java.util.concurrent.TimeUnit;
+
 public class Log4jShutdownOnContextDestroyedListener implements ServletContextListener {
 
     private static final int DEFAULT_STOP_TIMEOUT = 30;
@@ -65,16 +63,12 @@ public class Log4jShutdownOnContextDestroyedListener implements ServletContextLi
 
         this.initializer.clearLoggerContext(); // the application is finished
         // shutting down now
-        if (initializer instanceof LifeCycle2) {
-            final String stopTimeoutStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT);
-            final long stopTimeout = Strings.isEmpty(stopTimeoutStr) ? DEFAULT_STOP_TIMEOUT
-                    : Long.parseLong(stopTimeoutStr);
-            final String timeoutTimeUnitStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT_TIMEUNIT);
-            final TimeUnit timeoutTimeUnit = Strings.isEmpty(timeoutTimeUnitStr) ? DEFAULT_STOP_TIMEOUT_TIMEUNIT
-                    : TimeUnit.valueOf(timeoutTimeUnitStr.toUpperCase(Locale.ROOT));
-            ((LifeCycle2) this.initializer).stop(stopTimeout, timeoutTimeUnit);
-        } else {
-            this.initializer.stop();
-        }
+        final String stopTimeoutStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT);
+        final long stopTimeout = Strings.isEmpty(stopTimeoutStr) ? DEFAULT_STOP_TIMEOUT
+                : Long.parseLong(stopTimeoutStr);
+        final String timeoutTimeUnitStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT_TIMEUNIT);
+        final TimeUnit timeoutTimeUnit = Strings.isEmpty(timeoutTimeUnitStr) ? DEFAULT_STOP_TIMEOUT_TIMEUNIT
+                : TimeUnit.valueOf(timeoutTimeUnitStr.toUpperCase(Locale.ROOT));
+        this.initializer.stop(stopTimeout, timeoutTimeUnit);
     }
 }
diff --git a/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jServletContextListener.java b/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jServletContextListener.java
index 4b8b267f21..d27b5896d2 100644
--- a/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jServletContextListener.java
+++ b/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jServletContextListener.java
@@ -16,17 +16,15 @@
  */
 package org.apache.logging.log4j.web;
 
-import java.util.Locale;
-import java.util.concurrent.TimeUnit;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.Strings;
 
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
-
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LifeCycle2;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.util.Strings;
+import java.util.Locale;
+import java.util.concurrent.TimeUnit;
 
 /**
  * In environments older than Servlet 3.0, this initializer is responsible for starting up Log4j logging before anything
@@ -78,16 +76,12 @@ public class Log4jServletContextListener implements ServletContextListener {
 
 		this.initializer.clearLoggerContext(); // the application is finished
 		// shutting down now
-		if (initializer instanceof LifeCycle2) {
-			final String stopTimeoutStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT);
-			final long stopTimeout = Strings.isEmpty(stopTimeoutStr) ? DEFAULT_STOP_TIMEOUT
-					: Long.parseLong(stopTimeoutStr);
-			final String timeoutTimeUnitStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT_TIMEUNIT);
-			final TimeUnit timeoutTimeUnit = Strings.isEmpty(timeoutTimeUnitStr) ? DEFAULT_STOP_TIMEOUT_TIMEUNIT
-					: TimeUnit.valueOf(timeoutTimeUnitStr.toUpperCase(Locale.ROOT));
-			((LifeCycle2) this.initializer).stop(stopTimeout, timeoutTimeUnit);
-		} else {
-			this.initializer.stop();
-		}
+		final String stopTimeoutStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT);
+		final long stopTimeout = Strings.isEmpty(stopTimeoutStr) ? DEFAULT_STOP_TIMEOUT
+				: Long.parseLong(stopTimeoutStr);
+		final String timeoutTimeUnitStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT_TIMEUNIT);
+		final TimeUnit timeoutTimeUnit = Strings.isEmpty(timeoutTimeUnitStr) ? DEFAULT_STOP_TIMEOUT_TIMEUNIT
+				: TimeUnit.valueOf(timeoutTimeUnitStr.toUpperCase(Locale.ROOT));
+		this.initializer.stop(stopTimeout, timeoutTimeUnit);
 	}
 }
diff --git a/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jShutdownOnContextDestroyedListener.java b/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jShutdownOnContextDestroyedListener.java
index e65dca8b48..75160fd263 100644
--- a/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jShutdownOnContextDestroyedListener.java
+++ b/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jShutdownOnContextDestroyedListener.java
@@ -16,17 +16,15 @@
  */
 package org.apache.logging.log4j.web;
 
-import java.util.Locale;
-import java.util.concurrent.TimeUnit;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.Strings;
 
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
-
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LifeCycle2;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.util.Strings;
+import java.util.Locale;
+import java.util.concurrent.TimeUnit;
 
 public class Log4jShutdownOnContextDestroyedListener implements ServletContextListener {
 
@@ -65,16 +63,12 @@ public class Log4jShutdownOnContextDestroyedListener implements ServletContextLi
 
         this.initializer.clearLoggerContext(); // the application is finished
         // shutting down now
-        if (initializer instanceof LifeCycle2) {
-            final String stopTimeoutStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT);
-            final long stopTimeout = Strings.isEmpty(stopTimeoutStr) ? DEFAULT_STOP_TIMEOUT
-                    : Long.parseLong(stopTimeoutStr);
-            final String timeoutTimeUnitStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT_TIMEUNIT);
-            final TimeUnit timeoutTimeUnit = Strings.isEmpty(timeoutTimeUnitStr) ? DEFAULT_STOP_TIMEOUT_TIMEUNIT
-                    : TimeUnit.valueOf(timeoutTimeUnitStr.toUpperCase(Locale.ROOT));
-            ((LifeCycle2) this.initializer).stop(stopTimeout, timeoutTimeUnit);
-        } else {
-            this.initializer.stop();
-        }
+        final String stopTimeoutStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT);
+        final long stopTimeout = Strings.isEmpty(stopTimeoutStr) ? DEFAULT_STOP_TIMEOUT
+                : Long.parseLong(stopTimeoutStr);
+        final String timeoutTimeUnitStr = servletContext.getInitParameter(KEY_STOP_TIMEOUT_TIMEUNIT);
+        final TimeUnit timeoutTimeUnit = Strings.isEmpty(timeoutTimeUnitStr) ? DEFAULT_STOP_TIMEOUT_TIMEUNIT
+                : TimeUnit.valueOf(timeoutTimeUnitStr.toUpperCase(Locale.ROOT));
+        this.initializer.stop(stopTimeout, timeoutTimeUnit);
     }
 }


[logging-log4j2] 02/02: Only clean up files before tests

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit d1c265e71498a1c7fa97a8d9e6369d97ec3a19b8
Author: Matt Sicker <ma...@apache.org>
AuthorDate: Sat Jun 18 13:20:14 2022 -0500

    Only clean up files before tests
    
    This should hopefully alleviate Windows-specific issues where files are attempted to be deleted while they're in use.
    
    Signed-off-by: Matt Sicker <ma...@apache.org>
---
 .../org/apache/logging/log4j/test/junit/AbstractFileCleaner.java  | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/AbstractFileCleaner.java b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/AbstractFileCleaner.java
index c6aa8739fc..7a3b2e0405 100644
--- a/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/AbstractFileCleaner.java
+++ b/log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/AbstractFileCleaner.java
@@ -18,7 +18,6 @@
 package org.apache.logging.log4j.test.junit;
 
 import org.apache.commons.io.file.PathUtils;
-import org.junit.jupiter.api.extension.AfterEachCallback;
 import org.junit.jupiter.api.extension.BeforeEachCallback;
 import org.junit.jupiter.api.extension.ExtensionContext;
 
@@ -35,7 +34,7 @@ import java.util.stream.Collectors;
 
 import static org.junit.jupiter.api.Assertions.fail;
 
-abstract class AbstractFileCleaner implements BeforeEachCallback, AfterEachCallback {
+abstract class AbstractFileCleaner implements BeforeEachCallback {
 
     public static final String MAX_TRIES_PROPERTY = "log4j2.junit.fileCleanerMaxTries";
     public static final String SLEEP_PERIOD_MILLIS_PROPERTY = "log4j2.junit.fileCleanerSleepPeriodMillis";
@@ -45,11 +44,6 @@ abstract class AbstractFileCleaner implements BeforeEachCallback, AfterEachCallb
         clean(context);
     }
 
-    @Override
-    public void afterEach(final ExtensionContext context) throws Exception {
-        clean(context);
-    }
-
     private void clean(final ExtensionContext context) {
         final Collection<Path> paths = getPathsForTest(context);
         if (paths.isEmpty()) {