Skip to content

Commit

Permalink
CAMEL-619: Fixed tracer not outputting node ids. Added unit test for …
Browse files Browse the repository at this point in the history
…tracer. Breadcrum is outputtet to be used for correlation for poor end users looking into the log files

git-svn-id: https://svn.apache.org/repos/asf/activemq/camel/trunk@671751 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
davsclaus committed Jun 26, 2008
1 parent 16b5ec7 commit 5436a23
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 12 deletions.
Expand Up @@ -80,8 +80,8 @@ public void done(boolean doneSynchronously) {
}

protected void recordTime(Exchange exchange, double duration) {
if (LOG.isDebugEnabled()) {
LOG.debug("Recording duration: " + duration + " millis for exchange: " + exchange);
if (LOG.isTraceEnabled()) {
LOG.trace("Recording duration: " + duration + " millis for exchange: " + exchange);
}

if (!exchange.isFailed() && exchange.getException() == null) {
Expand Down
Expand Up @@ -100,7 +100,7 @@ public Processor wrapProcessorInInterceptors(ProcessorType processorType, Proces
DebugInterceptor interceptor = new DebugInterceptor(processorType, target, createExchangeList(), createExceptionsList());
interceptors.put(id, interceptor);
if (LOG.isDebugEnabled()) {
LOG.debug("adding interceptor: " + interceptor);
LOG.debug("Adding " + id + " interceptor: " + interceptor);
}
return interceptor;
}
Expand Down
Expand Up @@ -24,12 +24,12 @@
* @version $Revision: 1.1 $
*/
public class TraceFormatter {
private boolean showBreadCrumb = true;
private boolean showNode = true;
private boolean showExchangeId;
private boolean showProperties = true;
private boolean showHeaders = true;
private boolean showBody = true;
private boolean showExchangeId;
private boolean showBreadCrumb;

public Object format(TraceInterceptor interceptor, Exchange exchange) {
Message in = exchange.getIn();
Expand All @@ -45,7 +45,6 @@ public Object format(TraceInterceptor interceptor, Exchange exchange) {
+ (exception != null ? " Exception: " + exception : "");
}


public boolean isShowBody() {
return showBody;
}
Expand Down Expand Up @@ -109,8 +108,8 @@ protected Object getBodyAsString(Message in) {
return answer;
}


protected String getNodeMessage(TraceInterceptor interceptor) {
return interceptor.getNode().getId();
}

}
Expand Up @@ -30,6 +30,10 @@ public class Tracer implements InterceptStrategy {
private TraceFormatter formatter = new TraceFormatter();

public Processor wrapProcessorInInterceptors(ProcessorType processorType, Processor target) throws Exception {
// Force the creation of an id, otherwise the id is not available when the trace formatter is
// outputting trace information
String id = processorType.idOrCreate();
return new TraceInterceptor(processorType, target, formatter);
}

}
@@ -0,0 +1,57 @@
/**
* 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.camel.processor;

import org.apache.camel.ContextTestSupport;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.processor.interceptor.Debugger;

/**
* @version $Revision$
*/
public class DebugInterceptorTest extends ContextTestSupport {

public void testSendingSomeMessages() throws Exception {
template.sendBodyAndHeader("direct:start", "Hello London", "to", "James");
template.sendBodyAndHeader("direct:start", "This is Copenhagen calling", "from", "Claus");
}

protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
getContext().addInterceptStrategy(new Debugger());

from("direct:start").
process(new Processor() {
public void process(Exchange exchange) throws Exception {
// do nothing
}

@Override
public String toString() {
return "MyProcessor";
}
}).
to("mock:a").
to("mock:b");
}
};
}

}
Expand Up @@ -21,22 +21,22 @@
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.processor.interceptor.Debugger;
import org.apache.camel.processor.interceptor.Tracer;

/**
* @version $Revision: 1.1 $
*/
public class TraceInterceptorTest extends ContextTestSupport {

public void testSendingSomeMessages() throws Exception {
template.sendBodyAndHeader("direct:start", "body1", "header1", "value1");
template.sendBodyAndHeader("direct:start", "body2", "header1", "value2");
template.sendBodyAndHeader("direct:start", "Hello London", "to", "James");
template.sendBodyAndHeader("direct:start", "This is Copenhagen calling", "from", "Claus");
}


protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
// lets add the debugger which traces by default
getContext().addInterceptStrategy(new Debugger());
getContext().addInterceptStrategy(new Tracer());

from("direct:start").
process(new Processor() {
Expand All @@ -54,4 +54,5 @@ public String toString() {
}
};
}

}

0 comments on commit 5436a23

Please sign in to comment.