[logback-dev] svn commit: r2121 - in logback/trunk: logback-access/src/main/java/ch/qos/logback/access logback-access/src/main/java/ch/qos/logback/access/jetty logback-classic/src/main/java/ch/qos/logback/classic logback-site/src/site/pages logback-site/src/site/pages/manual logback-site/src/site/resources/images logback-site/src/site/resources/manual/images/chapter3

noreply.ceki at qos.ch noreply.ceki at qos.ch
Fri Jan 9 18:31:18 CET 2009


Author: ceki
Date: Fri Jan  9 18:31:17 2009
New Revision: 2121

Added:
   logback/trunk/logback-site/src/site/resources/images/lbAccessStatus.jpg   (contents, props changed)
   logback/trunk/logback-site/src/site/resources/manual/images/chapter3/lbClassicStatus.jpg   (contents, props changed)
Modified:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/ViewStatusMessagesServlet.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/ViewStatusMessagesServlet.java
   logback/trunk/logback-site/src/site/pages/access.html
   logback/trunk/logback-site/src/site/pages/manual/joran.html

Log:
Fixing LBCORE-81 and LBCORE-82.  

- Added StatusMessage viewer servlet for lb-classic called ViewStatusMessagesServlet. 

- Added StatusMessage viewer servlet for lb-access called ViewStatusMessagesServlet. 
  It works with Tomcat but not Jetty.

- Added relevant documentation.


Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/ViewStatusMessagesServlet.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/ViewStatusMessagesServlet.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/ViewStatusMessagesServlet.java	Fri Jan  9 18:31:17 2009
@@ -9,6 +9,7 @@
  */
 package ch.qos.logback.access;
 
+import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -20,8 +21,24 @@
   private static final long serialVersionUID = 443878494348593337L;
 
   @Override
-  protected StatusManager getStatusManager(HttpServletRequest req, HttpServletResponse resp) {
-    return (StatusManager) req.getAttribute(AccessConstants.LOGBACK_STATUS_MANAGER_KEY);
+  protected StatusManager getStatusManager(HttpServletRequest req,
+      HttpServletResponse resp) {
+
+    ServletContext sc = getServletContext();
+    StatusManager result = (StatusManager) sc
+        .getAttribute(AccessConstants.LOGBACK_STATUS_MANAGER_KEY);
+    return result;
+    
+//    if (result != null) {
+//      System.out.println("from ServletContext");
+//      return result;
+//    } else {
+//      HttpSession httpSession = req.getSession(true);
+//      
+//      System.out.println("from httpSession");
+//      return (StatusManager) httpSession
+//          .getAttribute(AccessConstants.LOGBACK_STATUS_MANAGER_KEY);
+//    }
   }
 
   @Override

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java	Fri Jan  9 18:31:17 2009
@@ -4,7 +4,7 @@
 import java.util.HashMap;
 import java.util.Iterator;
 
-import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
 
 import org.mortbay.jetty.Request;
 import org.mortbay.jetty.RequestLog;
@@ -92,7 +92,7 @@
  *      <appender-ref ref="SMTP" /> 
  *    </configuration>
  * </pre>
-
+ * 
  * @author Ceki G&uuml;lc&uuml;
  * @author S&eacute;bastien Pennec
  */
@@ -106,8 +106,7 @@
   FilterAttachableImpl<AccessEvent> fai = new FilterAttachableImpl<AccessEvent>();
   String filename;
   boolean started = false;
-  boolean alreadySetLogbackStatusManager = false;
-  
+
   public RequestLogImpl() {
     putObject(CoreConstants.EVALUATOR_MAP, new HashMap());
   }
@@ -118,18 +117,12 @@
     AccessEvent accessEvent = new AccessEvent(jettyRequest, jettyResponse,
         adapter);
 
-    if (!alreadySetLogbackStatusManager) {
-      alreadySetLogbackStatusManager = true;
-      ServletContext sc = jettyRequest.getContext();
-      // servlet context is always null
-      if (sc != null) {
-        sc.setAttribute(AccessConstants.LOGBACK_STATUS_MANAGER_KEY,
-            getStatusManager());
-      }
+    HttpSession s = jettyRequest.getSession();
+    if (s != null) {
+      System.out.println("Setting as session attribute");
+      s.setAttribute(AccessConstants.LOGBACK_STATUS_MANAGER_KEY,
+          getStatusManager());
     }
-
-    jettyRequest.setAttribute(
-        AccessConstants.LOGBACK_STATUS_MANAGER_KEY, getStatusManager());
     if (getFilterChainDecision(accessEvent) == FilterReply.DENY) {
       return;
     }

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/ViewStatusMessagesServlet.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/ViewStatusMessagesServlet.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/ViewStatusMessagesServlet.java	Fri Jan  9 18:31:17 2009
@@ -21,7 +21,6 @@
 
   private static final long serialVersionUID = 443878494348593337L;
 
-  //
 
   @Override
   protected StatusManager getStatusManager(HttpServletRequest req, HttpServletResponse resp) {

Modified: logback/trunk/logback-site/src/site/pages/access.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/access.html	(original)
+++ logback/trunk/logback-site/src/site/pages/access.html	Fri Jan  9 18:31:17 2009
@@ -111,9 +111,39 @@
     the logback-access configuration file. Here is an example.
     </p>
 
+   <p class="source">&lt;Valve className="ch.qos.logback.access.tomcat.LogbackValve"
+       quiet="true" filename="c:/my-logback-access.xml"/></p>
 
-    <div class="source"><pre>&lt;Valve className="ch.qos.logback.access.tomcat.LogbackValve"
-       quiet="true" filename="c:/my-logback-access.xml"/></pre></div>
+    <h3><a name="viewingStatusMessages"
+    href="#viewingStatusMessages">Viewing status messages</a></h3>
+
+    <p>Logback-access ships with a servlet called
+    <code>ViewStatusMessagesServlet</code>. This servlet prints the
+    internal status messages of the <code>LogbackValve</code> as an
+    HTML table. Here is sample output.
+    </p>
+
+
+    <a href="images/lbAccessStatus.jpg">
+     <img src="images/lbAccessStatus.jpg" alt="click to enlarge" width="90%"/>
+    </a>
+
+    <p>To add this servlet to your web-application, add the following
+    lines to its <em>WEB-INF/web.xml</em> file.</p>
+
+    <p class="source">  &lt;servlet>
+    &lt;servlet-name>AccessViewStatusMessages&lt;/servlet-name>
+    &lt;servlet-class>ch.qos.logback.access.ViewStatusMessagesServlet&lt;/servlet-class>
+  &lt;/servlet>
+
+  &lt;servlet-mapping>
+    &lt;servlet-name>AccessViewStatusMessages&lt;/servlet-name>
+    &lt;url-pattern>/lbAccessStatus&lt;/url-pattern>
+  &lt;/servlet-mapping></p>
+   
+    <p>The <code>ViewStatusMessages</code> servlet will available
+    under the URL <code>http://host/yourWebapp/lbAccessStatus</code>
+    </p>
     
     <a name="jetty"></a>
 		<h1>Logback-access under Jetty</h1>

Modified: logback/trunk/logback-site/src/site/pages/manual/joran.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/joran.html	(original)
+++ logback/trunk/logback-site/src/site/pages/manual/joran.html	Fri Jan  9 18:31:17 2009
@@ -409,15 +409,16 @@
    errors.
    </p>   
 
-  <h3>
-    <a name="statusListener" href="#statusListener">Listening to
-    status messages</a>
-  </h3>
-
-   <p>Logback collects its internal status data in its <code><a
-   href="../xref/ch/qos/logback/core/status/StatusManager.html">StatusManager</a></code>,
-   accessible via the LoggerContext.
-  </p>
+   <h3><a name="viewingStatusMessages"
+   href="#viewingStatusMessages">Viewing status messages</a>
+   </h3>
+
+
+
+   <p>Logback collects its internal status data in a <code><a
+   href="../xref/ch/qos/logback/core/status/StatusManager.html">StatusManager</a></code>
+   object, accessible via the <code>LoggerContext</code>.
+   </p>
 
    <p>Given a <code>StatusManager</code> you an access all the status
    data associated with a logback context. To keep memory usage at
@@ -428,6 +429,39 @@
    <em>T</em> messages. At present time <em>H</em>=<em>T</em>=150,
    although these values may change in future releases.</p>
 
+   <p>Logback-classic ships with a servlet called
+   ViewStatusMessagesServlet. This servlet prints the contents of the
+   <code>StatusManager</code> associated with the current
+   <code>LoggerContext</code> as an HTML table. Here is sample output.
+   </p>
+   
+   <a href="images/chapter3/lbClassicStatus.jpg">
+     <img src="images/chapter3/lbClassicStatus.jpg" alt="click to enlarge" width="90%"/>
+   </a>
+
+   <p>To add this servlet to your web-application, add the following
+   lines to its <em>WEB-INF/web.xml</em> file.</p>
+
+   <p class="source">  &lt;servlet>
+    &lt;servlet-name>ViewStatusMessages&lt;/servlet-name>
+    &lt;servlet-class>ch.qos.logback.classic.ViewStatusMessagesServlet&lt;/servlet-class>
+  &lt;/servlet>
+
+  &lt;servlet-mapping>
+    &lt;servlet-name>ViewStatusMessages&lt;/servlet-name>
+    &lt;url-pattern>/lbClassicStatus&lt;/url-pattern>
+  &lt;/servlet-mapping></p>
+   
+   <p>The <code>ViewStatusMessages</code> servlet will viewable under
+   the URL <code>http://host/yourWebapp/lbClassicStatus</code>
+   </p>
+
+   <h3>
+     <a name="statusListener" href="#statusListener">Listening to
+     status messages</a>
+   </h3>
+
+
 
    <p>You may also attach a <code>StatusListener</code> to a
    <code>StatusManager</code> so that you can take immediate action in
@@ -477,9 +511,12 @@
 
    <p class="source">java <b>-Dlogback.statusListenerClass</b>=ch.qos.logback.core.status.OnConsoleStatusListener&nbsp;...</p>
    
-  <h2>
-    <a name="syntax" href="#syntax">Configuration file Syntax</a>
-  </h2>
+
+
+
+   <h2>
+     <a name="syntax" href="#syntax">Configuration file Syntax</a>
+   </h2>
 
 	<p>To obtain these different logging behaviors we do not need to
 	recompile code.  You can easily configure logback so as to disable

Added: logback/trunk/logback-site/src/site/resources/images/lbAccessStatus.jpg
==============================================================================
Binary file. No diff available.

Added: logback/trunk/logback-site/src/site/resources/manual/images/chapter3/lbClassicStatus.jpg
==============================================================================
Binary file. No diff available.


More information about the logback-dev mailing list