Author: kkolinko
Date: Thu Aug  4 04:01:23 2011
New Revision: 1153745

URL: http://svn.apache.org/viewvc?rev=1153745&view=rev
Log:
Allow to have several AccessLogValve instances in the same scope (e.g. in the 
same Context).

Added:
    tomcat/trunk/java/org/apache/catalina/core/AccessLogAdapter.java   (with 
props)
Modified:
    tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java
    tomcat/trunk/webapps/docs/changelog.xml

Added: tomcat/trunk/java/org/apache/catalina/core/AccessLogAdapter.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/AccessLogAdapter.java?rev=1153745&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/AccessLogAdapter.java (added)
+++ tomcat/trunk/java/org/apache/catalina/core/AccessLogAdapter.java Thu Aug  4 
04:01:23 2011
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.catalina.core;
+
+import java.util.Arrays;
+
+import org.apache.catalina.AccessLog;
+import org.apache.catalina.connector.Request;
+import org.apache.catalina.connector.Response;
+
+/**
+ * A helper class that wraps several AccessLog instances.
+ */
+public class AccessLogAdapter implements AccessLog {
+
+    private AccessLog[] logs;
+
+    public AccessLogAdapter(AccessLog log) {
+        if (log == null) {
+            throw new NullPointerException();
+        }
+        logs = new AccessLog[] { log };
+    }
+
+    public void add(AccessLog log) {
+        if (log == null) {
+            throw new NullPointerException();
+        }
+        AccessLog newArray[] = Arrays.copyOf(logs, logs.length + 1);
+        newArray[newArray.length - 1] = log;
+        logs = newArray;
+    }
+
+    @Override
+    public void log(Request request, Response response, long time) {
+        for (AccessLog log: logs) {
+            log.log(request, response, time);
+        }
+    }
+
+    @Override
+    public void setRequestAttributesEnabled(boolean requestAttributesEnabled) {
+        // NOOP
+    }
+
+    @Override
+    public boolean getRequestAttributesEnabled() {
+        // NOOP. Could return logs[0].getRequestAttributesEnabled(), but I do
+        // not see a use case for that.
+        return false;
+    }
+
+}

Propchange: tomcat/trunk/java/org/apache/catalina/core/AccessLogAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java?rev=1153745&r1=1153744&r2=1153745&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java Thu Aug  4 
04:01:23 2011
@@ -1144,14 +1144,21 @@ public abstract class ContainerBase exte
         if (accessLogScanComplete) {
             return accessLog;
         }
-        
+
+        AccessLogAdapter adapter = null;
         Valve valves[] = getPipeline().getValves();
         for (Valve valve : valves) {
             if (valve instanceof AccessLog) {
-                accessLog = (AccessLog) valve;
-                break;
+                if (adapter == null) {
+                    adapter = new AccessLogAdapter((AccessLog) valve);
+                } else {
+                    adapter.add((AccessLog) valve);
+                }
             }
         }
+        if (adapter != null) {
+            accessLog = adapter;
+        }
         accessLogScanComplete = true;
         return accessLog;
     }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1153745&r1=1153744&r2=1153745&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Aug  4 04:01:23 2011
@@ -125,6 +125,10 @@
         conditional logging that logs only if a request attribute is present.
         (kkolinko)
       </add>
+      <fix>
+        Allow to have several AccessLogValve instances in the same scope (e.g.
+        in the same Context). (kkolinko)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to