From dbaa6ff624e0427aba0160e1947ae431e80b66e3 Mon Sep 17 00:00:00 2001 From: rfeng Date: Thu, 9 Jul 2009 19:13:08 +0000 Subject: Refine the logging Add info for the intents/policySets git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@792641 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/resources/LoggingMessages.properties | 16 +++++ .../src/main/resources/META-INF/definitions.xml | 34 +++++++++++ .../JDKLoggingImplementationPolicyProvider.java | 4 +- .../logging/jdk/JDKLoggingPolicyInterceptor.java | 70 +++++++++++++++------- .../jdk/JDKLoggingReferencePolicyProvider.java | 4 +- .../jdk/JDKLoggingServicePolicyProvider.java | 2 +- 6 files changed, 105 insertions(+), 25 deletions(-) create mode 100644 java/sca/itest/policies/src/main/resources/LoggingMessages.properties create mode 100644 java/sca/itest/policies/src/main/resources/META-INF/definitions.xml (limited to 'java') diff --git a/java/sca/itest/policies/src/main/resources/LoggingMessages.properties b/java/sca/itest/policies/src/main/resources/LoggingMessages.properties new file mode 100644 index 0000000000..09c0e7565d --- /dev/null +++ b/java/sca/itest/policies/src/main/resources/LoggingMessages.properties @@ -0,0 +1,16 @@ +# 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. diff --git a/java/sca/itest/policies/src/main/resources/META-INF/definitions.xml b/java/sca/itest/policies/src/main/resources/META-INF/definitions.xml new file mode 100644 index 0000000000..1698f885a5 --- /dev/null +++ b/java/sca/itest/policies/src/main/resources/META-INF/definitions.xml @@ -0,0 +1,34 @@ + + + + + + + FINE + LoggingMessages.properties + + + + + \ No newline at end of file diff --git a/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java b/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java index 85ce106048..66a0ba2b51 100644 --- a/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java +++ b/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java @@ -41,8 +41,8 @@ public class JDKLoggingImplementationPolicyProvider extends BasePolicyProvider policies = findPolicies(); - return policies.isEmpty() ? null : new JDKLoggingPolicyInterceptor(getContext(), operation, policies, - Phase.IMPLEMENTATION_POLICY); + return policies.isEmpty() ? null : new JDKLoggingPolicyInterceptor(subject, getContext(), operation, + policies, Phase.IMPLEMENTATION_POLICY); } } diff --git a/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyInterceptor.java b/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyInterceptor.java index 9200bfdd70..0c20d1fa84 100644 --- a/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyInterceptor.java +++ b/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyInterceptor.java @@ -26,10 +26,14 @@ import java.util.logging.Logger; import javax.xml.namespace.QName; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.PhasedInterceptor; +import org.apache.tuscany.sca.policy.PolicySubject; /** * Policy handler to handle PolicySet related to Logging with the QName @@ -45,23 +49,36 @@ public class JDKLoggingPolicyInterceptor implements PhasedInterceptor { private Invoker next; private Operation operation; private List policies; + private PolicySubject subject; private String context; private String phase; - public JDKLoggingPolicyInterceptor(String context, + public JDKLoggingPolicyInterceptor(PolicySubject subject, + String context, Operation operation, List policies, String phase) { super(); this.operation = operation; this.policies = policies; - this.context = context; + this.subject = subject; this.phase = phase; + this.context = getContext(); init(); } - public void start() { - init(); + private String getContext() { + if (subject instanceof Endpoint) { + Endpoint endpoint = (Endpoint)subject; + return endpoint.getURI(); + } else if (subject instanceof EndpointReference) { + EndpointReference endpointReference = (EndpointReference)subject; + return endpointReference.getURI(); + } else if (subject instanceof Component) { + Component component = (Component)subject; + return component.getURI(); + } + return null; } private void init() { @@ -83,31 +100,38 @@ public class JDKLoggingPolicyInterceptor implements PhasedInterceptor { consoleHandler.setLevel(Level.ALL); logger.addHandler(consoleHandler); } + + if (logger.isLoggable(Level.FINE)) { + logger.logp(Level.FINE, context, "", "Intents: {0}", subject.getRequiredIntents()); + logger.logp(Level.FINE, context, "", "PolicySets: {0}", subject.getPolicySets()); + } } public Message invoke(Message msg) { if (logger == null) { return getNext().invoke(msg); } + logger.logp(Level.INFO, context, "", "Invoking operation - " + operation.getName()); Object msgBody = msg.getBody(); if (msgBody instanceof Object[]) { - logger.logp(Level.INFO, context, "", "Invoking operation - " + operation.getName()); - - StringBuffer sb = new StringBuffer(); - if (msgBody == null) { - sb.append(""); - } else { - Object[] args = (Object[])msgBody; - for (int i = 0; i < args.length; i++) { - sb.append(args[i]); - if (i != args.length - 1) { - sb.append(", "); + + if (logger.isLoggable(Level.FINE)) { + StringBuffer sb = new StringBuffer(); + if (msgBody == null) { + sb.append(""); + } else { + Object[] args = (Object[])msgBody; + for (int i = 0; i < args.length; i++) { + sb.append(args[i]); + if (i != args.length - 1) { + sb.append(", "); + } } } - } - Object[] logParams = new Object[] {operation.getName(), sb.toString()}; - logger.logp(Level.FINER, context, "", "Invoking operation {0} with arguments {1}", logParams); + Object[] logParams = new Object[] {operation.getName(), sb.toString()}; + logger.logp(Level.FINE, context, "", "Invoking operation {0} with arguments {1}", logParams); + } } Message responseMsg = null; @@ -119,9 +143,15 @@ public class JDKLoggingPolicyInterceptor implements PhasedInterceptor { throw e; } finally { if (responseMsg != null) { - Object[] logParams = new Object[] {operation.getName(), responseMsg.getBody()}; logger.logp(Level.INFO, context, "", "Returned from operation - " + operation.getName()); - logger.logp(Level.FINER, context, "", "Returning from operation {0} with return value {1}", logParams); + if (logger.isLoggable(Level.FINE)) { + Object[] logParams = new Object[] {operation.getName(), responseMsg.getBody()}; + logger.logp(Level.FINE, + context, + "", + "Returning from operation {0} with return value {1}", + logParams); + } } } } diff --git a/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.java b/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.java index b10fd7345a..80867f57de 100644 --- a/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.java +++ b/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.java @@ -38,8 +38,8 @@ public class JDKLoggingReferencePolicyProvider extends BasePolicyProvider policies = findPolicies(); - return policies.isEmpty() ? null : new JDKLoggingPolicyInterceptor(getContext(), operation, policies, - Phase.REFERENCE_POLICY); + return policies.isEmpty() ? null : new JDKLoggingPolicyInterceptor(subject, getContext(), operation, + policies, Phase.REFERENCE_POLICY); } } diff --git a/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java b/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java index 1af1d05fe8..99f0563603 100644 --- a/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java +++ b/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java @@ -38,7 +38,7 @@ public class JDKLoggingServicePolicyProvider extends BasePolicyProvider policies = findPolicies(); - return policies.isEmpty() ? null : new JDKLoggingPolicyInterceptor(getContext(), operation, policies, Phase.SERVICE_POLICY); + return policies.isEmpty() ? null : new JDKLoggingPolicyInterceptor(subject, getContext(), operation, policies, Phase.SERVICE_POLICY); } } -- cgit v1.2.3