logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1385196 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/config/ core/src/test/java/org/apache/logging/log4j/core/config/ web/src/main/java/org/apache/logging/log4j/core/web/
Date Sat, 15 Sep 2012 22:58:28 GMT
Author: rgoers
Date: Sat Sep 15 22:58:27 2012
New Revision: 1385196

URL: http://svn.apache.org/viewvc?rev=1385196&view=rev
Log:
Pass the LoggerContext to Configurator.shutdown()

Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
    logging/log4j/log4j2/trunk/web/src/main/java/org/apache/logging/log4j/core/web/Log4jContextListener.java

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java?rev=1385196&r1=1385195&r2=1385196&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
Sat Sep 15 22:58:27 2012
@@ -18,11 +18,8 @@ package org.apache.logging.log4j.core.co
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.core.LoggerContext;
-import org.xml.sax.InputSource;
 
-import java.io.File;
 import java.net.URI;
-import java.net.URL;
 
 /**
  * Class that can be used to initialize and configure the Logging system.
@@ -37,7 +34,7 @@ public final class Configurator {
      * @param name The Context name.
      * @param loader The ClassLoader for the Context (or null).
      * @param configLocation The configuration for the logging context.
-     * @return
+     * @return The LoggerContext.
      */
     public static LoggerContext intitalize(String name, ClassLoader loader, String configLocation)
{
 
@@ -53,9 +50,10 @@ public final class Configurator {
         return null;
     }
 
-    public static void shutdown() {
-        LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
-        ctx.setConfiguration(new DefaultConfiguration());
+    public static void shutdown(LoggerContext ctx) {
+        if (ctx != null) {
+            ctx.setConfiguration(new DefaultConfiguration());
+        }
     }
 
 }

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java?rev=1385196&r1=1385195&r2=1385196&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
Sat Sep 15 22:58:27 2012
@@ -41,9 +41,8 @@ public class TestConfigurator {
 
     @Test
     public void testFromFile() throws Exception {
-        Configurator.intitalize("Test1", null, "target/test-classes/log4j2-config.xml");
+        LoggerContext ctx = Configurator.intitalize("Test1", null, "target/test-classes/log4j2-config.xml");
         Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator");
-        LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
         Configuration config = ctx.getConfiguration();
         assertNotNull("No configuration", config);
         assertTrue("Incorrect Configuration. Expected " + CONFIG_NAME + " but found " + config.getName(),
@@ -51,7 +50,7 @@ public class TestConfigurator {
         Map<String, Appender> map = config.getAppenders();
         assertNotNull("No Appenders", map != null && map.size() > 0);
         assertTrue("Wrong configuration", map.containsKey("List"));
-        Configurator.shutdown();
+        Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
         assertTrue("Incorrect Configuration. Expected " + DefaultConfiguration.DEFAULT_NAME
+ " but found " +
             config.getName(), DefaultConfiguration.DEFAULT_NAME.equals(config.getName()));
@@ -59,9 +58,8 @@ public class TestConfigurator {
 
     @Test
     public void testFromClassPath() throws Exception {
-        Configurator.intitalize("Test1", null, "log4j2-config.xml");
+        LoggerContext ctx = Configurator.intitalize("Test1", null, "log4j2-config.xml");
         Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator");
-        LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
         Configuration config = ctx.getConfiguration();
         assertNotNull("No configuration", config);
         assertTrue("Incorrect Configuration. Expected " + CONFIG_NAME + " but found " + config.getName(),
@@ -69,7 +67,7 @@ public class TestConfigurator {
         Map<String, Appender> map = config.getAppenders();
         assertNotNull("No Appenders", map != null && map.size() > 0);
         assertTrue("Wrong configuration", map.containsKey("List"));
-        Configurator.shutdown();
+        Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
         assertTrue("Incorrect Configuration. Expected " + DefaultConfiguration.DEFAULT_NAME
+ " but found " +
             config.getName(), DefaultConfiguration.DEFAULT_NAME.equals(config.getName()));
@@ -77,9 +75,8 @@ public class TestConfigurator {
 
     @Test
     public void testByName() throws Exception {
-        Configurator.intitalize("-config", null, null);
+        LoggerContext ctx = Configurator.intitalize("-config", null, null);
         Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator");
-        LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
         Configuration config = ctx.getConfiguration();
         assertNotNull("No configuration", config);
         assertTrue("Incorrect Configuration. Expected " + CONFIG_NAME + " but found " + config.getName(),
@@ -87,7 +84,7 @@ public class TestConfigurator {
         Map<String, Appender> map = config.getAppenders();
         assertNotNull("No Appenders", map != null && map.size() > 0);
         assertTrue("Wrong configuration", map.containsKey("List"));
-        Configurator.shutdown();
+        Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
         assertTrue("Incorrect Configuration. Expected " + DefaultConfiguration.DEFAULT_NAME
+ " but found " +
             config.getName(), DefaultConfiguration.DEFAULT_NAME.equals(config.getName()));
@@ -97,9 +94,8 @@ public class TestConfigurator {
     public void testReconfiguration() throws Exception {
         File file = new File("target/test-classes/log4j2-config.xml");
         file.setLastModified(System.currentTimeMillis() - 120000);
-        Configurator.intitalize("Test1", null, "target/test-classes/log4j2-config.xml");
+        LoggerContext ctx = Configurator.intitalize("Test1", null, "target/test-classes/log4j2-config.xml");
         Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator");
-        LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
         Configuration config = ctx.getConfiguration();
         assertNotNull("No configuration", config);
         assertTrue("Incorrect Configuration. Expected " + CONFIG_NAME + " but found " + config.getName(),
@@ -115,7 +111,7 @@ public class TestConfigurator {
         }
         Configuration newConfig = ctx.getConfiguration();
         assertTrue("Configuration not reset", newConfig != config);
-        Configurator.shutdown();
+        Configurator.shutdown(ctx);
         config = ctx.getConfiguration();
         assertTrue("Incorrect Configuration. Expected " + DefaultConfiguration.DEFAULT_NAME
+ " but found " +
             config.getName(), DefaultConfiguration.DEFAULT_NAME.equals(config.getName()));

Modified: logging/log4j/log4j2/trunk/web/src/main/java/org/apache/logging/log4j/core/web/Log4jContextListener.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/web/src/main/java/org/apache/logging/log4j/core/web/Log4jContextListener.java?rev=1385196&r1=1385195&r2=1385196&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/web/src/main/java/org/apache/logging/log4j/core/web/Log4jContextListener.java
(original)
+++ logging/log4j/log4j2/trunk/web/src/main/java/org/apache/logging/log4j/core/web/Log4jContextListener.java
Sat Sep 15 22:58:27 2012
@@ -17,7 +17,7 @@
 package org.apache.logging.log4j.core.web;
 
 import org.apache.logging.log4j.core.config.Configurator;
-import org.apache.logging.log4j.core.helpers.Loader;
+import org.apache.logging.log4j.core.LoggerContext;
 
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
@@ -38,8 +38,6 @@ public class Log4jContextListener implem
 
     public static final String LOG4J_CONTEXT_NAME = "log4jContextName";
 
-    private static final String CLASSES = "WEB-INF/classes";
-
     public void contextInitialized(ServletContextEvent event) {
         ServletContext context = event.getServletContext();
         String locn = context.getInitParameter(LOG4J_CONFIG);
@@ -55,8 +53,8 @@ public class Log4jContextListener implem
     }
 
     public void contextDestroyed(ServletContextEvent event) {
-        event.getServletContext().removeAttribute(LOG4J_CONTEXT_ATTRIBUTE);
-        Configurator.shutdown();
+        LoggerContext ctx = (LoggerContext) event.getServletContext().getAttribute(LOG4J_CONTEXT_ATTRIBUTE);
+        Configurator.shutdown(ctx);
     }
 
     private ClassLoader getClassLoader(ServletContext context) {



Mime
View raw message