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 2014/09/21 21:38:21 UTC

[1/3] git commit: Use WebLoggerContextUtils.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master b461f006b -> ed66e1fb8


Use WebLoggerContextUtils.


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/fd0cc438
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/fd0cc438
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/fd0cc438

Branch: refs/heads/master
Commit: fd0cc438bfa8ef9c5563439b6bf69c950db0357a
Parents: b461f00
Author: Matt Sicker <ma...@apache.org>
Authored: Sun Sep 21 14:07:34 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Sun Sep 21 14:07:34 2014 -0500

----------------------------------------------------------------------
 .../log4j/web/Log4jServletContainerInitializer.java       |  2 +-
 .../logging/log4j/web/Log4jServletContextListener.java    |  2 +-
 .../org/apache/logging/log4j/web/Log4jServletFilter.java  |  2 +-
 .../apache/logging/log4j/web/Log4jWebInitializerImpl.java | 10 ----------
 .../logging/log4j/web/Log4jWebInitializerImplTest.java    |  2 +-
 .../org/apache/logging/log4j/web/ServletAppenderTest.java |  9 ++++-----
 .../java/org/apache/logging/log4j/web/WebLookupTest.java  |  4 ++--
 7 files changed, 10 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fd0cc438/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jServletContainerInitializer.java
----------------------------------------------------------------------
diff --git a/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jServletContainerInitializer.java b/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jServletContainerInitializer.java
index 034e074..aad1b63 100644
--- a/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jServletContainerInitializer.java
+++ b/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jServletContainerInitializer.java
@@ -53,7 +53,7 @@ public class Log4jServletContainerInitializer implements ServletContainerInitial
                 return;
             }
 
-            final Log4jWebLifeCycle initializer = Log4jWebInitializerImpl.getLog4jWebInitializer(servletContext);
+            final Log4jWebLifeCycle initializer = WebLoggerContextUtils.getWebLifeCycle(servletContext);
             initializer.start();
             initializer.setLoggerContext(); // the application is just now starting to start up
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fd0cc438/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jServletContextListener.java
----------------------------------------------------------------------
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 4cf9022..35f4aae 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
@@ -40,7 +40,7 @@ public class Log4jServletContextListener implements ServletContextListener {
         this.servletContext = event.getServletContext();
         LOGGER.debug("Log4jServletContextListener ensuring that Log4j starts up properly.");
 
-        this.initializer = Log4jWebInitializerImpl.getLog4jWebInitializer(this.servletContext);
+        this.initializer = WebLoggerContextUtils.getWebLifeCycle(this.servletContext);
         try {
             this.initializer.start();
             this.initializer.setLoggerContext(); // the application is just now starting to start up

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fd0cc438/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jServletFilter.java
----------------------------------------------------------------------
diff --git a/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jServletFilter.java b/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jServletFilter.java
index e9283a7..e95f334 100644
--- a/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jServletFilter.java
+++ b/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jServletFilter.java
@@ -53,7 +53,7 @@ public class Log4jServletFilter implements Filter {
         this.servletContext = filterConfig.getServletContext();
         LOGGER.debug("Log4jServletFilter initialized.");
 
-        this.initializer = Log4jWebInitializerImpl.getLog4jWebInitializer(this.servletContext);
+        this.initializer = WebLoggerContextUtils.getWebLifeCycle(this.servletContext);
         this.initializer.clearLoggerContext(); // the application is mostly finished starting up now
     }
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fd0cc438/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java
----------------------------------------------------------------------
diff --git a/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java b/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java
index 826ecd2..8a67ce2 100644
--- a/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java
+++ b/log4j-web/src/main/java/org/apache/logging/log4j/web/Log4jWebInitializerImpl.java
@@ -256,14 +256,4 @@ final class Log4jWebInitializerImpl extends AbstractLifeCycle implements Log4jWe
         }
     }
 
-    /**
-     * Get the current initializer from the {@link ServletContext}. If the initializer does not exist, create a new one
-     * and add it to the {@link ServletContext}, then return that.
-     *
-     * @param servletContext The {@link ServletContext} for this web application
-     * @return the initializer, never {@code null}.
-     */
-    static Log4jWebLifeCycle getLog4jWebInitializer(final ServletContext servletContext) {
-        return WebLoggerContextUtils.getWebLifeCycle(servletContext);
-    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fd0cc438/log4j-web/src/test/java/org/apache/logging/log4j/web/Log4jWebInitializerImplTest.java
----------------------------------------------------------------------
diff --git a/log4j-web/src/test/java/org/apache/logging/log4j/web/Log4jWebInitializerImplTest.java b/log4j-web/src/test/java/org/apache/logging/log4j/web/Log4jWebInitializerImplTest.java
index 01d3d23..dc3f9e3 100644
--- a/log4j-web/src/test/java/org/apache/logging/log4j/web/Log4jWebInitializerImplTest.java
+++ b/log4j-web/src/test/java/org/apache/logging/log4j/web/Log4jWebInitializerImplTest.java
@@ -52,7 +52,7 @@ public class Log4jWebInitializerImplTest {
 
         replay(this.servletContext);
 
-        final Log4jWebLifeCycle initializer = Log4jWebInitializerImpl.getLog4jWebInitializer(this.servletContext);
+        final Log4jWebLifeCycle initializer = WebLoggerContextUtils.getWebLifeCycle(this.servletContext);
 
         assertNotNull("The initializer should not be null.", initializer);
         assertSame("The capture is not correct.", initializer, initializerCapture.getValue());

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fd0cc438/log4j-web/src/test/java/org/apache/logging/log4j/web/ServletAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-web/src/test/java/org/apache/logging/log4j/web/ServletAppenderTest.java b/log4j-web/src/test/java/org/apache/logging/log4j/web/ServletAppenderTest.java
index bcabf2d..e9bcc3d 100644
--- a/log4j-web/src/test/java/org/apache/logging/log4j/web/ServletAppenderTest.java
+++ b/log4j-web/src/test/java/org/apache/logging/log4j/web/ServletAppenderTest.java
@@ -16,6 +16,8 @@
 */
 package org.apache.logging.log4j.web;
 
+import javax.servlet.ServletContext;
+
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.Appender;
@@ -25,10 +27,7 @@ import org.apache.logging.log4j.core.impl.ContextAnchor;
 import org.junit.Test;
 import org.springframework.mock.web.MockServletContext;
 
-import javax.servlet.ServletContext;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 
 /**
  *
@@ -46,7 +45,7 @@ public class ServletAppenderTest {
         servletContext.setAttribute("Name1", "Ben");
         servletContext.setInitParameter("Name2", "Jerry");
         servletContext.setInitParameter(Log4jWebSupport.LOG4J_CONFIG_LOCATION, CONFIG);
-        final Log4jWebLifeCycle initializer = Log4jWebInitializerImpl.getLog4jWebInitializer(servletContext);
+        final Log4jWebLifeCycle initializer = WebLoggerContextUtils.getWebLifeCycle(servletContext);
         try {
             initializer.start();
             initializer.setLoggerContext();

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fd0cc438/log4j-web/src/test/java/org/apache/logging/log4j/web/WebLookupTest.java
----------------------------------------------------------------------
diff --git a/log4j-web/src/test/java/org/apache/logging/log4j/web/WebLookupTest.java b/log4j-web/src/test/java/org/apache/logging/log4j/web/WebLookupTest.java
index e66a42d..6cf8a6b 100644
--- a/log4j-web/src/test/java/org/apache/logging/log4j/web/WebLookupTest.java
+++ b/log4j-web/src/test/java/org/apache/logging/log4j/web/WebLookupTest.java
@@ -41,7 +41,7 @@ public class WebLookupTest {
         servletContext.setInitParameter("TestParam", "ParamValue");
         servletContext.setAttribute("Name1", "Ben");
         servletContext.setInitParameter("Name2", "Jerry");
-        final Log4jWebLifeCycle initializer = Log4jWebInitializerImpl.getLog4jWebInitializer(servletContext);
+        final Log4jWebLifeCycle initializer = WebLoggerContextUtils.getWebLifeCycle(servletContext);
         try {
             initializer.start();
             initializer.setLoggerContext();
@@ -80,7 +80,7 @@ public class WebLookupTest {
         servletContext.setAttribute("Name1", "Ben");
         servletContext.setInitParameter("Name2", "Jerry");
         servletContext.setInitParameter("log4jConfiguration", "log4j-webvar.xml");
-        final Log4jWebLifeCycle initializer = Log4jWebInitializerImpl.getLog4jWebInitializer(servletContext);
+        final Log4jWebLifeCycle initializer = WebLoggerContextUtils.getWebLifeCycle(servletContext);
         initializer.start();
         initializer.setLoggerContext();
         final LoggerContext ctx = ContextAnchor.THREAD_CONTEXT.get();


[3/3] git commit: Clean up webapp manual page.

Posted by ma...@apache.org.
Clean up webapp manual page.

  - More links.
  - class="javadoc" links.
  - Some grammar.


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/ed66e1fb
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/ed66e1fb
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/ed66e1fb

Branch: refs/heads/master
Commit: ed66e1fb87408e7116e4460e5b816c2189e73011
Parents: f9be39b
Author: Matt Sicker <ma...@apache.org>
Authored: Sun Sep 21 14:38:17 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Sun Sep 21 14:38:17 2014 -0500

----------------------------------------------------------------------
 src/site/xdoc/manual/webapp.xml | 66 +++++++++++++++++++++---------------
 1 file changed, 38 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ed66e1fb/src/site/xdoc/manual/webapp.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/webapp.xml b/src/site/xdoc/manual/webapp.xml
index 49cc039..ecad1f9 100644
--- a/src/site/xdoc/manual/webapp.xml
+++ b/src/site/xdoc/manual/webapp.xml
@@ -41,26 +41,31 @@
         <a href="../maven-artifacts.html">Maven, Ivy, and Gradle Artifacts</a> manual page.
       </p>
       <p class="big-red">
+        <i class="icon-exclamation-sign"/>
         To avoid problems the Log4j shutdown hook will automatically be disabled when the log4j-web jar is included.
       </p>
       <a name="Configuration"/>
       <subsection name="Configuration">
-        <p>Log4j allows the configuration file to be specified in web.xml using the log4jConfiguration context parameter.
-          Log4j will search for configuration files by:
-          </p>
-          <ol>
-              <li>If a location is provided it will be searched for as a servlet context resource. For example,
-                  if log4jConfiguration contains "logging.xml" then Log4j will look for a file with that name in the
-                  root directory of the web application.
-              </li>
-              <li>If no location is defined Log4j will search for a file that starts with "log4j2" in the WEB-INF directory.
-                  If more than one file is found then if a file that starts with "log4j2-<i>name</i>", where <i>name</i> is the
-                  name of the web application, is present it will be used. Otherwise the first file will be used.
-              </li>
-              <li>The "normal" search sequence using the classpath and file URLs will be used to locate the configuration
-                  file.
-              </li>
-          </ol>
+        <p>
+          Log4j allows the configuration file to be specified in web.xml using the <code>log4jConfiguration</code>
+          context parameter. Log4j will search for configuration files by:
+        </p>
+        <ol>
+          <li>
+            If a location is provided it will be searched for as a servlet context resource. For example, if
+            <code>log4jConfiguration</code> contains "logging.xml" then Log4j will look for a file with that
+            name in the root directory of the web application.
+          </li>
+          <li>
+            If no location is defined Log4j will search for a file that starts with "log4j2" in the WEB-INF directory.
+            If more than one file is found, and if a file that starts with "log4j2-<var>name</var>" is present, where
+            <var>name</var> is the name of the web application, then it will be used. Otherwise the first file will be
+            used.
+          </li>
+          <li>
+            The "normal" search sequence using the classpath and file URLs will be used to locate the configuration file.
+          </li>
+        </ol>
       </subsection>
       <subsection name="Servlet 3.0 and Newer Web Applications">
         <a name="Servlet-3.0" />
@@ -73,10 +78,14 @@
         <h4>The Short Story</h4>
         <p>
           Log4j 2 "just works" in Servlet 3.0 and newer web applications. It is capable of automatically starting when
-          the application deploys and shutting down when the application undeploys.
+          the application deploys and shutting down when the application undeploys. Thanks to the
+          <a class="javadoc" href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContainerInitializer.html">ServletContainerInitializer</a>
+          API added to Servlet 3.0, the relevant <code>Filter</code> and <code>ServletContextListener</code> classes
+          can be registered dynamically on web application startup.
         </p>
         <p>
-          <b><em>Important Note!</em></b> For performance reasons, containers often ignore certain JARs known not to
+          <strong class="text-warning"><i class="icon-exclamation-sign"/> Important Note!</strong>
+          For performance reasons, containers often ignore certain JARs known not to
           contain TLDs or <code>ServletContainerInitializer</code>s and do not scan them for web-fragments and
           initializers. Importantly, Tomcat 7 &lt;7.0.43 ignores all JAR files named log4j*.jar, which prevents this
           feature from working. This has been fixed in Tomcat 7.0.43, Tomcat 8, and later. In Tomcat 7 &lt;7.0.43 you
@@ -85,13 +94,13 @@
         </p>
         <h4>The Long Story</h4>
         <p>
-          The Log4j 2 Core JAR file is a web-fragment configured to order before any other web fragments in your
+          The Log4j 2 Web JAR file is a web-fragment configured to order before any other web fragments in your
           application. It contains a <code>ServletContainerInitializer</code>
-          (<a href="../log4j-core/apidocs/org/apache/logging/log4j/web/Log4jServletContainerInitializer.html"
+          (<a class="javadoc" href="../log4j-core/apidocs/org/apache/logging/log4j/web/Log4jServletContainerInitializer.html"
             >Log4jServletContainerInitializer</a>) that the container automatically discovers and initializes. This adds
-          the <a href="../log4j-core/apidocs/org/apache/logging/log4j/web/Log4jServletContextListener.html"
+          the <a class="javadoc" href="../log4j-core/apidocs/org/apache/logging/log4j/web/Log4jServletContextListener.html"
             >Log4jServletContextListener</a> and
-          <a href="../log4j-core/apidocs/org/apache/logging/log4j/web/Log4jServletFilter.html"
+          <a class="javadoc" href="../log4j-core/apidocs/org/apache/logging/log4j/web/Log4jServletFilter.html"
             >Log4jServletFilter</a> to the <code>ServletContext</code>. These classes properly initialize
           and deinitialize the Log4j configuration.
         </p>
@@ -134,9 +143,9 @@
         <p>
           If you are using Log4j in a Servlet 2.5 web application, or if you have disabled auto-initialization with
           the <code>isLog4jAutoInitializationDisabled</code> context parameter, you <em>must</em> configure the
-          <a href="../log4j-core/apidocs/org/apache/logging/log4j/web/Log4jServletContextListener.html"
+          <a class="javadoc" href="../log4j-core/apidocs/org/apache/logging/log4j/web/Log4jServletContextListener.html"
             >Log4jServletContextListener</a> and
-          <a href="../log4j-core/apidocs/org/apache/logging/log4j/web/Log4jServletFilter.html"
+          <a class="javadoc" href="../log4j-core/apidocs/org/apache/logging/log4j/web/Log4jServletFilter.html"
             >Log4jServletFilter</a> in the deployment descriptor or programmatically. The filter should match all
           requests of any type. The listener should be the very first listener defined in your application, and the
           filter should be the very first filter defined and mapped in your application. This is easily accomplished
@@ -172,7 +181,7 @@
           and uses the standard pattern for locating the Log4j configuration file. There are three context parameters
           that you can use to control this behavior. The first, <code>isLog4jContextSelectorNamed</code>, specifies
           whether the context should be selected using the
-          <a href="../log4j-core/apidocs/org/apache/logging/log4j/core/selector/JndiContextSelector.html"
+          <a class="javadoc" href="../log4j-core/apidocs/org/apache/logging/log4j/core/selector/JndiContextSelector.html"
             >JndiContextSelector</a>. If <code>isLog4jContextSelectorNamed</code> is not specified or is anything other
           than <code>true</code>, it is assumed to be <code>false</code>.
         </p>
@@ -219,7 +228,7 @@
     </context-param>]]></pre>
         <p>
           Note that in this case you must also set the "Log4jContextSelector" system property to
-          "org.apache.logging.log4j.core.selector.JndiContextSelector."
+          "<kbd>org.apache.logging.log4j.core.selector.JndiContextSelector</kbd>".
         </p>
       </subsection>
       <subsection name="Using Web Application Information During the Configuration">
@@ -245,7 +254,8 @@
           Library documentation.</a>
         </p>
         <p>
-          <b><em>Important Note!</em></b> As noted above, containers often ignore certain JARs known not to
+          <strong class="text-warning"><i class="icon-exclamation-sign"/> Important Note!</strong>
+          As noted above, containers often ignore certain JARs known not to
           contain TLDs and do not scan them for TLD files. Importantly, Tomcat 7 &lt;7.0.43 ignores all JAR files named
           log4j*.jar, which prevents the JSP tag library from being automatically discovered. This does not affect
           Tomcat 6.x and has been fixed in Tomcat 7.0.43, Tomcat 8, and later. In Tomcat 7 &lt;7.0.43 you
@@ -343,7 +353,7 @@ public class TestAsyncServlet extends HttpServlet {
         ]]></pre>
         <p>
           Alternatively, you can obtain the
-          <a href="../log4j-core/apidocs/org/apache/logging/log4j/web/Log4jWebLifeCycle.html">Log4jWebLifeCycle</a>
+          <a class="javadoc" href="../log4j-core/apidocs/org/apache/logging/log4j/web/Log4jWebLifeCycle.html">Log4jWebLifeCycle</a>
           instance from the <code>ServletContext</code> attributes, call its <code>setLoggerContext</code> method as
           the very first line of code in your asynchronous thread, and call its <code>clearLoggerContext</code> method
           as the very last line of code in your asynchronous thread. The following code demonstrates this. It uses the


[2/3] git commit: Add link to manual page in javadoc.

Posted by ma...@apache.org.
Add link to manual page in javadoc.


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f9be39b8
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f9be39b8
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f9be39b8

Branch: refs/heads/master
Commit: f9be39b8a117c3aec2a643164b45f73b3849409f
Parents: fd0cc43
Author: Matt Sicker <ma...@apache.org>
Authored: Sun Sep 21 14:08:31 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Sun Sep 21 14:08:31 2014 -0500

----------------------------------------------------------------------
 .../src/main/java/org/apache/logging/log4j/web/package-info.java   | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f9be39b8/log4j-web/src/main/java/org/apache/logging/log4j/web/package-info.java
----------------------------------------------------------------------
diff --git a/log4j-web/src/main/java/org/apache/logging/log4j/web/package-info.java b/log4j-web/src/main/java/org/apache/logging/log4j/web/package-info.java
index a33b859..3a918a8 100644
--- a/log4j-web/src/main/java/org/apache/logging/log4j/web/package-info.java
+++ b/log4j-web/src/main/java/org/apache/logging/log4j/web/package-info.java
@@ -18,5 +18,7 @@
 /**
  * The classes in this package are responsible for properly initializing and deinitializing Log4j in a Java EE web
  * application.
+ *
+ * @see <a href="http://logging.apache.org/log4j/2.x/manual/webapp.html">Using Log4j 2 in Web Applications</a>
  */
 package org.apache.logging.log4j.web;