Author: ceki
Date: Thu Mar 27 22:37:15 2008
New Revision: 1666

Modified:
   
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/joran/action/ConfigurationAction.java
   
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java
   logback/trunk/logback-site/src/site/pages/access.html
   logback/trunk/logback-site/src/site/pages/news.html

Log:
- LogbackValve in logback-access (ensuring integration with
  Tomcat), will now systematically print its internal status upon
  initialization, unless told to be quiet. This greatly helps
  troubleshooting the configration of logback-access under Tomcat.

Modified: 
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/joran/action/ConfigurationAction.java
==============================================================================
--- 
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/joran/action/ConfigurationAction.java
      (original)
+++ 
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/joran/action/ConfigurationAction.java
      Thu Mar 27 22:37:15 2008
@@ -38,8 +38,8 @@
   }
 
   public void end(InterpretationContext ec, String name) {
+    addInfo("End of configuration.");
     if (debugMode) {
-      addInfo("End of configuration.");
       StatusPrinter.print(context);
     }
     

Modified: 
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java
==============================================================================
--- 
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java
   (original)
+++ 
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java
   Thu Mar 27 22:37:15 2008
@@ -8,6 +8,8 @@
 
 import javax.servlet.ServletException;
 
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleListener;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
 import org.apache.catalina.valves.ValveBase;
@@ -25,6 +27,7 @@
 import ch.qos.logback.core.spi.FilterAttachable;
 import ch.qos.logback.core.spi.FilterAttachableImpl;
 import ch.qos.logback.core.spi.FilterReply;
+import ch.qos.logback.core.status.InfoStatus;
 import ch.qos.logback.core.status.StatusManager;
 import ch.qos.logback.core.status.WarnStatus;
 import ch.qos.logback.core.util.StatusPrinter;
@@ -33,37 +36,10 @@
  * This class is an implementation of tomcat's Valve interface, by extending
  * ValveBase.
  * 
- * It can be seen as logback classic's LoggerContext. Appenders can be attached
- * directly to LogbackValve and LogbackValve uses the same StatusManager as
- * LoggerContext does. It also provides containers for properties.
- * <p>
- * To configure tomcat in order to use LogbackValve, the following lines must 
be
- * added to the tomcat's server.xml, nested in an <code>Engine</code> element:
- * <p>
- * &lt;Valve className="ch.qos.logback.access.tomcat.LogbackValve"/&gt;
- * <p>
- * By default, LogbackValve looks for a logback configuration file called
- * logback-access.xml, in the same folder where the tomcat configuration is 
located,
- * that is $TOMCAT_HOME/conf/logback-access.xml. The format of logback-access 
configuration file 
- * is only slightly different than for logback-classic. Most of it remains the 
same:
- * Appenders and Layouts are declared the same way. However, since 
logback-access has 
- * no notion of declared loggers, logger elements are not allowed.
- * <p>
- * Here is a sample logback.xml file that can be used right away:
+ * <p>For more information on using LogbackValve please refer to the online 
+ * documentation on <a 
href="http://logback.qos.ch/access.html#tomcat";>logback-acces and tomcat</a>.
  * 
- * <pre>
- *  &lt;configuration&gt; 
- *    &lt;appender name=&quot;STDOUT&quot; 
class=&quot;ch.qos.logback.core.ConsoleAppender&quot;&gt; 
- *      &lt;layout class=&quot;ch.qos.logback.access.PatternLayout&quot;&gt; 
- *        &lt;param name=&quot;Pattern&quot; value=&quot;%date %server 
%remoteIP %clientHost %user %requestURL &quot; /&gt;
- *      &lt;/layout&gt; 
- *    &lt;/appender&gt; 
- *              
- *    &lt;appender-ref ref=&quot;STDOUT&quot; /&gt; 
- *  &lt;/configuration&gt;
- * </pre>
- * 
- * A special, module-specific implementation of PatternLayout was implemented 
to
+ * <p>A special, module-specific implementation of PatternLayout was 
implemented to
  * allow http-specific patterns to be used. The
  * [EMAIL PROTECTED] ch.qos.logback.access.PatternLayout} provides a way to 
format the
  * logging output that is just as easy and flexible as the usual PatternLayout.
@@ -76,7 +52,7 @@
  * @author Ceki G&uuml;lc&uuml;
  * @author S&eacute;bastien Pennec
  */
-public class LogbackValve extends ValveBase implements Context,
+public class LogbackValve extends ValveBase implements Lifecycle, Context,
     AppenderAttachable<AccessEvent>, FilterAttachable {
 
   public final static String DEFAULT_CONFIG_FILE = "conf" + File.separatorChar
@@ -94,11 +70,11 @@
 
   AppenderAttachableImpl<AccessEvent> aai = new 
AppenderAttachableImpl<AccessEvent>();
   String filename;
+  boolean quiet;
   boolean started;
 
   public LogbackValve() {
     putObject(CoreGlobal.EVALUATOR_MAP, new HashMap());
-    start();
   }
 
   public void start() {
@@ -107,9 +83,8 @@
 
       filename = tomcatHomeProperty + File.separatorChar + DEFAULT_CONFIG_FILE;
       getStatusManager().add(
-          new WarnStatus("filename property not set. Assuming [" + filename
+          new InfoStatus("filename property not set. Assuming [" + filename
               + "]", this));
-
     }
     File configFile = new File(filename);
     if (configFile.exists()) {
@@ -118,15 +93,37 @@
         jc.setContext(this);
         jc.doConfigure(filename);
       } catch (JoranException e) {
-        StatusPrinter.print(getStatusManager());
+        // TODO can we do better than printing a stack trace on syserr?
+        e.printStackTrace();
       }
     } else {
       getStatusManager().add(
           new WarnStatus("[" + filename + "] does not exist", this));
     }
+
+    if(!quiet) {
+      StatusPrinter.print(getStatusManager());
+    }
+
     started = true;
   }
 
+  public String getFilename() {
+    return filename;
+  }
+
+  public void setFilename(String filename) {
+     this.filename = filename;
+  }
+  
+  public boolean isQuiet() {
+    return quiet;
+  }
+
+  public void setQuiet(boolean quiet) {
+    this.quiet = quiet;
+  }
+
   public void invoke(Request request, Response response) throws IOException,
       ServletException {
 
@@ -134,11 +131,11 @@
 
     TomcatServerAdapter adapter = new TomcatServerAdapter(request, response);
     AccessEvent accessEvent = new AccessEvent(request, response, adapter);
-    
+
     if (getFilterChainDecision(accessEvent) == FilterReply.DENY) {
       return;
     }
-    
+
     // TODO better exception handling
     aai.appendLoopOnAppenders(accessEvent);
   }
@@ -232,4 +229,21 @@
     }
     this.name = name;
   }
+
+
+
+  // Methods from catalina Lifecycle
+
+  public void addLifecycleListener(LifecycleListener arg0) {
+    // dummy NOP implementation
+  }
+
+  public LifecycleListener[] findLifecycleListeners() {
+    return new LifecycleListener[0];
+  }
+
+  public void removeLifecycleListener(LifecycleListener arg0) {
+    // dummy NOP implementation
+  }
+
 }

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       Thu Mar 27 
22:37:15 2008
@@ -29,34 +29,47 @@
 
                <h1>Introduction</h1>
 
+    <p>The logback-access module integrates with Servlet containers
+    such as Jetty or Tomcat to provide rich and powerful HTTP-access
+    log functionality.
+    </p>
+               
                <p>Logback was designed as a modular framework from the
-               start. Making logback-core reusable under different 
circumstances,
-               without much recoding was one of our main goals. As such,
-               logback-access builds on top of logback-core. It fully 
integrates
-               with Servlet containers such as Jetty or Tomcat to provide
-               HTTP-access log functionality.
-               </p>
+               start. Making logback-core reusable under different 
circumstances
+               without much recoding was one of our main goals. In accordance
+               with this strategy, logback-access builds on top of
+               logback-core. </p>
 
     <a name="tomcat"></a>
-               <h2>Logback-access and Tomcat</h2>
+               <h1>Logback-access under Tomcat</h1>
                
                <p>To use logback-access with Tomcat, after downlading the 
logback
                distribution, place the files <em>logback-core-VERSION.jar</em>
                and <em>logback-access-VERSION.jar</em> under
-               $TOMCAT_HOME/server/lib directory, where $TOMCAT_HOME is the
-               folder where you have installed Tomcat. We have tested
-               logback-access module with Tomcat version 5.5.20.
+               $TOMCAT_HOME/<b>server/lib/</b> directory, where $TOMCAT_HOME is
+               the folder where you have installed Tomcat. We have tested
+               logback-access module with Tomcat version 5.5.26.
                </p>
+
+    <p>If you place the logback-core and logback-access jars in
+    $TOMCAT_HOME/server/lib <em>and</em> your webapps do not use
+    logback-classic, then everything should be fine. If however your
+    webapps do indeed use logback-classic, you must make sure to
+    bundle <code>logback-core.jar</code> under your webapps'
+    WEB-INF/lib directory. An alternative strategy is to place
+    logback-core.jar under $TOMCAT_HOME/common/lib. In that case, you
+    no longer need to place logback-core.jar in your web-apps.
+    </p>
                
-               <h3>LogbackValve</h3>
+               <h2>LogbackValve</h2>
 
                <p>The <a
                href="xref/ch/qos/logback/access/tomcat/LogbackValve.html">
                <code>ch.qos.logback.access.tomcat.LogbackValve</code></a> class
                extends Tomcat's <code><a
                
href="http://tomcat.apache.org/tomcat-5.5-doc/catalina/docs/api/org/apache/catalina/valves/ValveBase.html";>
-               ValveBase</a></code> class. This class is used to allow external
-               components to be integrated into Tomcat.
+               ValveBase</a></code> class. Valves are usually associated 
together
+               to form a processing pipeline.
                </p>
        
                <p>To configure Tomcat in order to use 
<code>LogbackValve</code>,
@@ -73,14 +86,36 @@
                <em>server.xml</em> is located, that is in
                <em>$TOMCAT_HOME/conf/</em>. This configuration file contains
                directives for configuring logback-access components. It is used
-               to specify appenders where the logging requests will be their
-               format, and filters. Please refer to the <a
-               href="#configuration">section discussing</a> this subject 
further
-               below.
-       </p>
+               to specify appenders where the logging requests will be
+               sent. Please refer to the <a 
href="#configuration">logback-access
+               configuration section</a> further below.
+    </p>
                
+    <p>In order to help with troubleshooting, by default, the
+    LogbackValve will print its internal status at its
+    initialization. Typical output would look as:
+    </p>
+    
+    <p class="source">21:56:09,921 |-INFO in 
c.q.lb.access.j.a.ConfigurationAction - Ignoring debug attribute.
+21:56:09,921 |-INFO in c.q.lb.core.j.a.AppenderAction - About to instantiate 
appender of type [ch.qos.logback.core.ConsoleAppender]
+21:56:09,921 |-INFO in c.q.lb.core.j.a.AppenderAction - Naming appender as 
[STDOUT]
+21:56:10,000 |-INFO in c.q.lb.core.j.a.NestedComponentIA - Pushing component 
[layout] on top of the object stack.
+21:56:10,015 |-INFO in c.q.lb.core.j.a.AppenderAction - Popping appender named 
[STDOUT] from the object stack
+21:56:10,015 |-INFO in c.q.lb.core.j.a.AppenderRefAction - Attaching appender 
named [STDOUT] to ch.qos.logback.access.tomcat.LogbackValve[Catalina]
+21:56:10,015 |-INFO in c.q.lb.access.j.a.ConfigurationAction - End of 
configuration.</p>
+
+    <p>It is possible to override default status printing by specifing
+    the "quiet" attribute in the <code>Valve</code>
+    element. Similarly, it is also possible to set the filename for
+    the logback-access configuration file. Here is an example.
+    </p>
+
+
+    <div class="source"><pre>&lt;Valve 
className="ch.qos.logback.access.tomcat.LogbackValve"
+       quiet="true" filename="c:/my-logback-access.xml"/></pre></div>
+    
     <a name="jetty"></a>
-               <h2>Logback-access and Jetty</h2>
+               <h1>Logback-access under Jetty</h1>
 
                <p>After downlading the logback distribution, place the files
                <em>logback-core-VERSION.jar</em> and
@@ -145,7 +180,7 @@
 &lt;/Ref&gt;</pre></div>
 
   <a name="configuration"></a>
-       <h2>Logback-access configuration</h2>
+       <h1>Logback-access configuration</h1>
        
   <p>Altough similar, the <em>logback-access.xml</em> file is slightly
   different than its more common counterpart in logback-classic.

Modified: logback/trunk/logback-site/src/site/pages/news.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/news.html (original)
+++ logback/trunk/logback-site/src/site/pages/news.html Thu Mar 27 22:37:15 2008
@@ -28,8 +28,19 @@
 
 
   <hr width="80%" align="center" />
+
+  <h3>XXth of XXX 2008 - Release of version 0.9.10</h3>
+
+  <p>The LogbackValve in logback-access (ensuring integration with
+  Tomcat), will now systematically print its internal status upon
+  initialization, unless told to be quiet. This greatly helps
+  troubleshooting the configration of logback-access under Tomcat.
+  </p>
+  
+  <hr width="80%" align="center" />
  
 
+
   <h3>26th of March 2008 - Release of version 0.9.9</h3>
   
    <p>MDC data in now inherited by child threads. This behaviour was
_______________________________________________
logback-dev mailing list
[email protected]
http://qos.ch/mailman/listinfo/logback-dev

Reply via email to