Author: rfeng
Date: Thu Jul 9 19:13:08 2009
New Revision: 792641
URL: http://svn.apache.org/viewvc?rev=792641&view=rev
Log:
Refine the logging
Add info for the intents/policySets
Added:
tuscany/java/sca/itest/policies/src/main/resources/LoggingMessages.properties
tuscany/java/sca/itest/policies/src/main/resources/META-INF/definitions.xml
Modified:
tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java
tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyInterceptor.java
tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.java
tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java
Added:
tuscany/java/sca/itest/policies/src/main/resources/LoggingMessages.properties
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/itest/policies/src/main/resources/LoggingMessages.properties?rev=792641&view=auto
==============================================================================
---
tuscany/java/sca/itest/policies/src/main/resources/LoggingMessages.properties
(added)
+++
tuscany/java/sca/itest/policies/src/main/resources/LoggingMessages.properties
Thu Jul 9 19:13:08 2009
@@ -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.
Added:
tuscany/java/sca/itest/policies/src/main/resources/META-INF/definitions.xml
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/itest/policies/src/main/resources/META-INF/definitions.xml?rev=792641&view=auto
==============================================================================
--- tuscany/java/sca/itest/policies/src/main/resources/META-INF/definitions.xml
(added)
+++ tuscany/java/sca/itest/policies/src/main/resources/META-INF/definitions.xml
Thu Jul 9 19:13:08 2009
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * 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.
+-->
+<definitions xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.1"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1">
+
+ <policySet name="JDKLoggingPolicy"
+ provides="tuscany:logging"
+ appliesTo="binding|implementation">
+ <tuscany:jdkLogger name="test.logger">
+ <tuscany:logLevel>FINE</tuscany:logLevel>
+
<tuscany:resourceBundle>LoggingMessages.properties</tuscany:resourceBundle>
+ </tuscany:jdkLogger>
+
+ </policySet>
+
+</definitions>
\ No newline at end of file
Modified:
tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java?rev=792641&r1=792640&r2=792641&view=diff
==============================================================================
---
tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java
(original)
+++
tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingImplementationPolicyProvider.java
Thu Jul 9 19:13:08 2009
@@ -41,8 +41,8 @@
*/
public PhasedInterceptor createInterceptor(Operation operation) {
List<JDKLoggingPolicy> 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);
}
}
Modified:
tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyInterceptor.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyInterceptor.java?rev=792641&r1=792640&r2=792641&view=diff
==============================================================================
---
tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyInterceptor.java
(original)
+++
tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingPolicyInterceptor.java
Thu Jul 9 19:13:08 2009
@@ -26,10 +26,14 @@
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 @@
private Invoker next;
private Operation operation;
private List<JDKLoggingPolicy> policies;
+ private PolicySubject subject;
private String context;
private String phase;
- public JDKLoggingPolicyInterceptor(String context,
+ public JDKLoggingPolicyInterceptor(PolicySubject subject,
+ String context,
Operation operation,
List<JDKLoggingPolicy> 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 @@
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 @@
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);
+ }
}
}
}
Modified:
tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.java?rev=792641&r1=792640&r2=792641&view=diff
==============================================================================
---
tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.java
(original)
+++
tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingReferencePolicyProvider.java
Thu Jul 9 19:13:08 2009
@@ -38,8 +38,8 @@
public PhasedInterceptor createInterceptor(Operation operation) {
List<JDKLoggingPolicy> 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);
}
}
Modified:
tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java
URL:
http://svn.apache.org/viewvc/tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java?rev=792641&r1=792640&r2=792641&view=diff
==============================================================================
---
tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java
(original)
+++
tuscany/java/sca/modules/policy-logging/src/main/java/org/apache/tuscany/sca/policy/logging/jdk/JDKLoggingServicePolicyProvider.java
Thu Jul 9 19:13:08 2009
@@ -38,7 +38,7 @@
public PhasedInterceptor createInterceptor(Operation operation) {
List<JDKLoggingPolicy> 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);
}
}