Support logging of all response header values at AccessLogValve (ex. add %{Set-Cookie...
authorpero <pero@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 13 Sep 2007 19:31:16 +0000 (19:31 +0000)
committerpero <pero@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 13 Sep 2007 19:31:16 +0000 (19:31 +0000)
and ExtendedAccessLogValve (ex. add x-O(Set-Cookie) to your pattern)

git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@575411 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/valves/AccessLogValve.java
java/org/apache/catalina/valves/ExtendedAccessLogValve.java
webapps/docs/changelog.xml
webapps/docs/config/valve.xml

index 3556e74..ef3d6ab 100644 (file)
@@ -94,6 +94,7 @@ import org.apache.juli.logging.LogFactory;
  * 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 @@ import org.apache.juli.logging.LogFactory;
  * @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 @@ public class AccessLogValve
      * 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 @@ public class AccessLogValve
     }
 
     /**
+     * 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 @@ public class AccessLogValve
             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("???");
         }
index 858e9f8..12cbb7f 100644 (file)
@@ -64,6 +64,7 @@ import org.apache.juli.logging.LogFactory;
  * <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 @@ import org.apache.juli.logging.LogFactory;
  *
  *
  * @author Tim Funk
+ * @author Peter Rossbach
+ * 
  * @version $Revision$ $Date$
  */
 
@@ -138,7 +141,7 @@ public class ExtendedAccessLogValve
      * 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 @@ public class ExtendedAccessLogValve
         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 @@ public class ExtendedAccessLogValve
         }
     }
     
+    /**
+     * 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 @@ public class ExtendedAccessLogValve
             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);
index 8a85677..8edb17a 100644 (file)
       <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">
index e01a9be..68bf946 100644 (file)
     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>