From: kkolinko Date: Thu, 4 Aug 2011 04:01:23 +0000 (+0000) Subject: Allow to have several AccessLogValve instances in the same scope (e.g. in the same... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=1119a8982ad57eca0c8faaa8b5aa0e8a159bf2bc;p=tomcat7.0 Allow to have several AccessLogValve instances in the same scope (e.g. in the same Context). git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1153745 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/core/AccessLogAdapter.java b/java/org/apache/catalina/core/AccessLogAdapter.java new file mode 100644 index 000000000..935858d15 --- /dev/null +++ b/java/org/apache/catalina/core/AccessLogAdapter.java @@ -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; + } + +} diff --git a/java/org/apache/catalina/core/ContainerBase.java b/java/org/apache/catalina/core/ContainerBase.java index a2e6200fc..96fe008d1 100644 --- a/java/org/apache/catalina/core/ContainerBase.java +++ b/java/org/apache/catalina/core/ContainerBase.java @@ -1144,14 +1144,21 @@ public abstract class ContainerBase extends LifecycleMBeanBase 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; } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 5d1036f70..b7079996b 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -125,6 +125,10 @@ conditional logging that logs only if a request attribute is present. (kkolinko) + + Allow to have several AccessLogValve instances in the same scope (e.g. + in the same Context). (kkolinko) +