camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r788585 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/processor/ main/java/org/apache/camel/processor/interceptor/ test/java/org/apache/camel/component/seda/
Date Fri, 26 Jun 2009 05:43:20 GMT
Author: davsclaus
Date: Fri Jun 26 05:43:20 2009
New Revision: 788585

URL: http://svn.apache.org/viewvc?rev=788585&view=rev
Log:
CAMEL-1759 easier configuration of tracing from Java DSL

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/TracingWithDelayTest.java
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Logger.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceInterceptor.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Tracer.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Logger.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Logger.java?rev=788585&r1=788584&r2=788585&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Logger.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/Logger.java Fri Jun 26
05:43:20 2009
@@ -144,6 +144,45 @@
         }
     }
 
+    public void process(Exchange exchange, String message) {
+        switch (level) {
+        case DEBUG:
+            if (log.isDebugEnabled()) {
+                log.debug(logMessage(exchange, message));
+            }
+            break;
+        case ERROR:
+            if (log.isErrorEnabled()) {
+                log.error(logMessage(exchange, message));
+            }
+            break;
+        case FATAL:
+            if (log.isFatalEnabled()) {
+                log.fatal(logMessage(exchange, message));
+            }
+            break;
+        case INFO:
+            if (log.isInfoEnabled()) {
+                log.info(logMessage(exchange, message));
+            }
+            break;
+        case TRACE:
+            if (log.isTraceEnabled()) {
+                log.trace(logMessage(exchange, message));
+            }
+            break;
+        case WARN:
+            if (log.isWarnEnabled()) {
+                log.warn(logMessage(exchange, message));
+            }
+            break;
+        case OFF:
+            break;
+        default:
+            log.error("Unknown level: " + level + " when trying to log exchange: " + logMessage(exchange,
message));
+        }
+    }
+
     public void log(String message, LoggingLevel loggingLevel) {
         LoggingLevel oldLogLevel = getLevel();
         setLevel(loggingLevel);
@@ -240,6 +279,10 @@
         return formatter.format(exchange);
     }
 
+    protected Object logMessage(Exchange exchange, String message) {
+        return formatter.format(exchange) + message;
+    }
+
     public Log getLog() {
         return log;
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceInterceptor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceInterceptor.java?rev=788585&r1=788584&r2=788585&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceInterceptor.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceInterceptor.java
Fri Jun 26 05:43:20 2009
@@ -210,7 +210,11 @@
 
     protected void logException(Exchange exchange, Throwable throwable) {
         if (tracer.isTraceExceptions()) {
-            logger.process(exchange, throwable);
+            if (tracer.isLogStackTrace()) {
+                logger.process(exchange, throwable);
+            } else {
+                logger.process(exchange, ", Exception: " + throwable.toString());
+            }
         }
     }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Tracer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Tracer.java?rev=788585&r1=788584&r2=788585&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Tracer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Tracer.java
Fri Jun 26 05:43:20 2009
@@ -40,6 +40,7 @@
     private Predicate traceFilter;
     private boolean traceInterceptors;
     private boolean traceExceptions = true;
+    private boolean logStackTrace;
     private boolean traceOutExchanges;
     private String destinationUri;
     private Endpoint destination;
@@ -135,6 +136,17 @@
         this.traceExceptions = traceExceptions;
     }
 
+    public boolean isLogStackTrace() {
+        return logStackTrace;
+    }
+
+    /**
+     * Sets whether thrown exception stacktrace should be traced, if disabled then only the
exception message is logged
+     */
+    public void setLogStackTrace(boolean logStackTrace) {
+        this.logStackTrace = logStackTrace;
+    }
+
     public String getLogName() {
         return logName;
     }

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/TracingWithDelayTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/TracingWithDelayTest.java?rev=788585&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/TracingWithDelayTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/TracingWithDelayTest.java
Fri Jun 26 05:43:20 2009
@@ -0,0 +1,60 @@
+/**
+ * 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.component.seda;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @version $Revision$
+ */
+public class TracingWithDelayTest extends ContextTestSupport {
+
+    private static final Log LOG = LogFactory.getLog(TracingWithDelayTest.class);
+
+    public void testTracingWithDelay() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                getContext().setTracing(true);
+
+                from("direct:start").delay(10).to("mock:a").
+                        process(new Processor() {
+                            public void process(Exchange exchange) throws Exception {
+                                LOG.info("This is the processor being invoked between mock:a
and mock:b");
+                            }
+                        })
+                        .to("mock:b").to("direct:c");
+
+                from("direct:c").transform(constant("Bye World")).to("mock:result");
+            }
+        };
+    }
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/TracingWithDelayTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/component/seda/TracingWithDelayTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message