Author: pero
Date: Thu Sep 13 12:31:16 2007
New Revision: 575411

URL: http://svn.apache.org/viewvc?rev=575411&view=rev
Log:
Support logging of all response header values at AccessLogValve (ex. add 
%{Set-Cookie}o to your pattern)
and ExtendedAccessLogValve (ex. add x-O(Set-Cookie) to your pattern)

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java
    
tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/ExtendedAccessLogValve.java
    tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
    tomcat/tc6.0.x/trunk/webapps/docs/config/valve.xml

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java?rev=575411&r1=575410&r2=575411&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/AccessLogValve.java 
Thu Sep 13 12:31:16 2007
@@ -94,6 +94,7 @@
  * It is modeled after the apache syntax:
  * <ul>
  * <li><code>%{xxx}i</code> for incoming headers
+ * <li><code>%{xxx}o</code> for outgoing response headers
  * <li><code>%{xxx}c</code> for a specific cookie
  * <li><code>%{xxx}r</code> xxx is an attribute in the ServletRequest
  * <li><code>%{xxx}s</code> xxx is an attribute in the HttpSession
@@ -111,7 +112,9 @@
  * @author Jason Brittain
  * @author Remy Maucherat
  * @author Takayuki Kaneko
- * @version $Revision$ $Date: 2007-01-04 12:17:11 +0900
+ * @author Peter Rossbach
+ * 
+ * @version $Revision$ $Date$
  */
 
 public class AccessLogValve
@@ -140,7 +143,7 @@
      * The descriptive information about this implementation.
      */
     protected static final String info =
-        "org.apache.catalina.valves.AccessLogValve/2.0";
+        "org.apache.catalina.valves.AccessLogValve/2.1";
 
 
     /**
@@ -1248,6 +1251,34 @@
     }
 
     /**
+     * write a specific response header - %{xxx}o
+     */
+    protected class ResponseHeaderElement implements AccessLogElement {
+        private String header;
+
+        public ResponseHeaderElement(String header) {
+            this.header = header;
+        }
+        
+        public void addElement(StringBuffer buf, Date date, Request request,
+                Response response, long time) {
+           if (null != response) {
+                String[] values = response.getHeaderValues(header);
+                if(values.length > 0) {
+                    for (int i = 0; i < values.length; i++) {
+                        String string = values[i];
+                        buf.append(string) ;
+                        if(i+1<values.length)
+                            buf.append(",");
+                    }
+                    return ;
+                }
+            }
+            buf.append("-");
+        }
+    }
+    
+    /**
      * write an attribute in the ServletRequest - %{xxx}r
      */
     protected class RequestAttributeElement implements AccessLogElement {
@@ -1370,10 +1401,12 @@
             return new HeaderElement(header);
         case 'c':
             return new CookieElement(header);
+        case 'o':
+            return new ResponseHeaderElement(header);
         case 'r':
             return new RequestAttributeElement(header);
         case 's':
-            return new SessionAttributeElement(header);
+            return new SessionAttributeElement(header);            
         default:
             return new StringElement("???");
         }

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/ExtendedAccessLogValve.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/ExtendedAccessLogValve.java?rev=575411&r1=575410&r2=575411&view=diff
==============================================================================
--- 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/ExtendedAccessLogValve.java
 (original)
+++ 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/valves/ExtendedAccessLogValve.java
 Thu Sep 13 12:31:16 2007
@@ -64,6 +64,7 @@
  * <li><code>time-taken</code>:  Time (in seconds) taken to serve the 
request</li>
  * <li><code>x-A(XXX)</code>: Pull XXX attribute from the servlet context </li>
  * <li><code>x-C(XXX)</code>: Pull the first cookie of the name XXX </li>
+ * <li><code>x-O(XXX)</code>: Pull the all response header values XXX </li>
  * <li><code>x-R(XXX)</code>: Pull XXX attribute from the servlet request </li>
  * <li><code>x-S(XXX)</code>: Pull XXX attribute from the session </li>
  * <li><code>x-P(...)</code>:  Call request.getParameter(...)
@@ -122,6 +123,8 @@
  *
  *
  * @author Tim Funk
+ * @author Peter Rossbach
+ * 
  * @version $Revision$ $Date$
  */
 
@@ -138,7 +141,7 @@
      * The descriptive information about this implementation.
      */
     protected static final String extendedAccessLogInfo =
-        "org.apache.catalina.valves.ExtendedAccessLogValve/1.0";
+        "org.apache.catalina.valves.ExtendedAccessLogValve/2.1";
 
 
     // ------------------------------------------------------------- Properties
@@ -209,7 +212,7 @@
         super.open();
         if (currentLogFile.length()==0) {
             writer.println("#Fields: " + pattern);
-            writer.println("#Version: 1.0");
+            writer.println("#Version: 2.0");
             writer.println("#Software: " + ServerInfo.getServerInfo());
         }
     }
@@ -331,6 +334,36 @@
         }
     }
     
+    /**
+     * write a specific response header - x-O(xxx)
+     */
+    protected class ResponseAllHeaderElement implements AccessLogElement {
+        private String header;
+
+        public ResponseAllHeaderElement(String header) {
+            this.header = header;
+        }
+        
+        public void addElement(StringBuffer buf, Date date, Request request,
+                Response response, long time) {
+           if (null != response) {
+                String[] values = response.getHeaderValues(header);
+                if(values.length > 0) {
+                    StringBuffer buffer = new StringBuffer();
+                    for (int i = 0; i < values.length; i++) {
+                        String string = values[i];
+                        buffer.append(string) ;
+                        if(i+1<values.length)
+                            buffer.append(",");
+                    }
+                    buf.append(wrap(buffer.toString()));
+                    return ;
+                }
+            }
+            buf.append("-");
+        }
+    }
+    
     protected class RequestAttributeElement implements AccessLogElement { 
         private String attribute;
         
@@ -718,6 +751,8 @@
             return getServletRequestElement(parameter);
         } else if ("P".equals(token)) {
             return new RequestParameterElement(parameter);
+        } else if ("O".equals(token)) {
+            return new ResponseAllHeaderElement(parameter);
         }
         log.error("x param for servlet request, couldn't decode value: "
                 + token);

Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=575411&r1=575410&r2=575411&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Thu Sep 13 12:31:16 2007
@@ -65,6 +65,12 @@
       <add>
         Made session createTime accessible for all SessionManager via JMX 
(pero)
       </add>
+      <update>
+        <bug>43129</bug>: Support logging of all response header values at 
AccessLogValve (ex. add %{Set-Cookie}o to your pattern). (pero)
+      </update>
+      <add>
+        Support logging of all response header values at 
ExtendedAccessLogValve (ex. add x-O(Set-Cookie) to your pattern). (pero)
+      </add>     
     </changelog>
   </subsection>
   <subsection name="Coyote">

Modified: tomcat/tc6.0.x/trunk/webapps/docs/config/valve.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/config/valve.xml?rev=575411&r1=575410&r2=575411&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/config/valve.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/config/valve.xml Thu Sep 13 12:31:16 2007
@@ -187,6 +187,7 @@
     It is modeled after the apache syntax:
     <ul>
     <li><b><code>%{xxx}i</code></b> for incoming headers</li>
+    <li><b><code>%{xxx}o</code></b> for outgoing response headers</li>
     <li><b><code>%{xxx}c</code></b> for a specific cookie</li>
     <li><b><code>%{xxx}r</code></b> xxx is an attribute in the 
ServletRequest</li>
     <li><b><code>%{xxx}s</code></b> xxx is an attribute in the HttpSession</li>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to