openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1806941 - in /openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave: Meecrowave.java logging/log4j2/Log4j2Shutdown.java
Date Fri, 01 Sep 2017 12:15:43 GMT
Author: rmannibucau
Date: Fri Sep  1 12:15:42 2017
New Revision: 1806941

URL: http://svn.apache.org/viewvc?rev=1806941&view=rev
Log:
ensure we don't depend on org.apache.logging.log4j.LogManager in Meecrowave since we are not
bound to log4j2 explicitly in the code

Added:
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/Log4j2Shutdown.java
Modified:
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java?rev=1806941&r1=1806940&r2=1806941&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
Fri Sep  1 12:15:42 2017
@@ -40,12 +40,12 @@ import org.apache.commons.lang3.text.Str
 import org.apache.commons.lang3.text.StrSubstitutor;
 import org.apache.coyote.http2.Http2Protocol;
 import org.apache.johnzon.core.BufferStrategy;
-import org.apache.logging.log4j.LogManager;
 import org.apache.meecrowave.api.StartListening;
 import org.apache.meecrowave.api.StopListening;
 import org.apache.meecrowave.cxf.CxfCdiAutoSetup;
 import org.apache.meecrowave.io.IO;
 import org.apache.meecrowave.logging.jul.Log4j2Logger;
+import org.apache.meecrowave.logging.log4j2.Log4j2Shutdown;
 import org.apache.meecrowave.logging.openwebbeans.Log4j2LoggerFactory;
 import org.apache.meecrowave.logging.tomcat.Log4j2Log;
 import org.apache.meecrowave.logging.tomcat.LogFacade;
@@ -372,8 +372,6 @@ public class Meecrowave implements AutoC
     }
 
     public Meecrowave start() {
-        disableLog4jShutdownHook();
-
         if (configuration.getMeecrowaveProperties() != null && !"meecrowave.properties".equals(configuration.getMeecrowaveProperties()))
{
             configuration.loadFrom(configuration.getMeecrowaveProperties());
         }
@@ -389,11 +387,13 @@ public class Meecrowave implements AutoC
             final String[] toRestore = new String[]{
                     System.getProperty("openwebbeans.logging.factory"),
                     System.getProperty("org.apache.cxf.Logger"),
-                    System.getProperty("org.apache.tomcat.Logger")
+                    System.getProperty("org.apache.tomcat.Logger"),
+                    System.getProperty("log4j.shutdownHookEnabled")
             };
             System.setProperty("openwebbeans.logging.factory", Log4j2LoggerFactory.class.getName());
             System.setProperty("org.apache.cxf.Logger", Log4j2Logger.class.getName());
             System.setProperty("org.apache.tomcat.Logger", Log4j2Log.class.getName());
+            System.setProperty("log4j.shutdownHookEnabled", "false");
             postTask = () -> {
                 if (toRestore[0] == null) {
                     System.clearProperty("openwebbeans.logging.factory");
@@ -410,6 +410,13 @@ public class Meecrowave implements AutoC
                 } else {
                     System.setProperty("org.apache.tomcat.Logger", toRestore[2]);
                 }
+
+                new Log4j2Shutdown().run();
+                if (toRestore[3] == null) { // note this can be too late
+                    System.clearProperty("log4j.shutdownHookEnabled");
+                } else {
+                    System.setProperty("log4j.shutdownHookEnabled", toRestore[3]);
+                }
             };
         }
         if (configuration.quickSession) {
@@ -653,13 +660,6 @@ public class Meecrowave implements AutoC
         return this;
     }
 
-    private void disableLog4jShutdownHook() {
-        // magic flag to disable log4j shutdown hook
-        // we need this, otherwise we don't get any logs
-        // when Meecrowave is shutting down!
-        System.setProperty("log4j.shutdownHookEnabled", "false");
-    }
-
     private void broadcastHostEvent(final String event, final Host host) {
         switch (event) {
             case Lifecycle.AFTER_START_EVENT: {
@@ -790,17 +790,6 @@ public class Meecrowave implements AutoC
                     ofNullable(configuration.getPidFile()).ifPresent(File::delete);
                 }
             }
-
-            try {
-                // We disabled the log4j shutdown hook to gain more control and keep logs
during shutdown.
-                // See #disableLog4jShutdownHook()
-                // Otoh that means we need to shutdown Log4j manually.
-                // So here we go...
-                LogManager.shutdown();
-            } catch (Exception e) {
-                System.out.println("A problem happened when shutting down Log4j: " + e +
"\n" + e.getMessage());
-                System.clearProperty("log4j.shutdownHookEnabled");
-            }
         }
     }
 

Added: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/Log4j2Shutdown.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/Log4j2Shutdown.java?rev=1806941&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/Log4j2Shutdown.java
(added)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/Log4j2Shutdown.java
Fri Sep  1 12:15:42 2017
@@ -0,0 +1,36 @@
+/*
+ * 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.meecrowave.logging.log4j2;
+
+import org.apache.logging.log4j.LogManager;
+
+public class Log4j2Shutdown implements Runnable {
+    @Override
+    public void run() {
+        try {
+            // We disabled the log4j shutdown hook to gain more control and keep logs during
shutdown.
+            // See #disableLog4jShutdownHook()
+            // Otoh that means we need to shutdown Log4j manually.
+            // So here we go...
+            LogManager.shutdown();
+        } catch (final Exception e) {
+            System.out.println("A problem happened when shutting down Log4j: " + e + "\n"
+ e.getMessage());
+        }
+    }
+}



Mime
View raw message