You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/08/01 06:37:17 UTC
[camel] branch master updated: CAMEL-13036: Allow advice with to
turn off logging routes before/after as XML
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 7312e3c CAMEL-13036: Allow advice with to turn off logging routes before/after as XML
7312e3c is described below
commit 7312e3cb035a07559b1cc16dafd6eb9cbc64fe26
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Aug 1 08:36:53 2019 +0200
CAMEL-13036: Allow advice with to turn off logging routes before/after as XML
---
.../camel/builder/AdviceWithRouteBuilder.java | 25 ++++++++++++++++++++++
.../org/apache/camel/reifier/RouteReifier.java | 20 ++++++++++++-----
2 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/core/camel-core/src/main/java/org/apache/camel/builder/AdviceWithRouteBuilder.java b/core/camel-core/src/main/java/org/apache/camel/builder/AdviceWithRouteBuilder.java
index e7163a6..d29061c 100644
--- a/core/camel-core/src/main/java/org/apache/camel/builder/AdviceWithRouteBuilder.java
+++ b/core/camel-core/src/main/java/org/apache/camel/builder/AdviceWithRouteBuilder.java
@@ -43,6 +43,7 @@ public abstract class AdviceWithRouteBuilder extends RouteBuilder {
private RouteDefinition originalRoute;
private final List<AdviceWithTask> adviceWithTasks = new ArrayList<>();
+ private boolean logRouteAsXml = true;
/**
* Advices this route with the route builder using a lambda expression.
@@ -121,6 +122,30 @@ public abstract class AdviceWithRouteBuilder extends RouteBuilder {
}
/**
+ * Whether to log the adviced routes before/after as XML.
+ * This is usable to know how the route was adviced and changed.
+ * However marshalling the route model to XML costs CPU resources
+ * and you can then turn this off by not logging.
+ *
+ * This is default enabled.
+ */
+ public boolean isLogRouteAsXml() {
+ return logRouteAsXml;
+ }
+
+ /**
+ * Sets whether to log the adviced routes before/after as XML.
+ * This is usable to know how the route was adviced and changed.
+ * However marshalling the route model to XML costs CPU resources
+ * and you can then turn this off by not logging.
+ *
+ * This is default enabled.
+ */
+ public void setLogRouteAsXml(boolean logRouteAsXml) {
+ this.logRouteAsXml = logRouteAsXml;
+ }
+
+ /**
* Gets a list of additional tasks to execute after the {@link #configure()} method has been executed
* during the advice process.
*
diff --git a/core/camel-core/src/main/java/org/apache/camel/reifier/RouteReifier.java b/core/camel-core/src/main/java/org/apache/camel/reifier/RouteReifier.java
index ec490e3..f940531 100644
--- a/core/camel-core/src/main/java/org/apache/camel/reifier/RouteReifier.java
+++ b/core/camel-core/src/main/java/org/apache/camel/reifier/RouteReifier.java
@@ -139,8 +139,11 @@ public class RouteReifier extends ProcessorReifier<RouteDefinition> {
// inject this route into the advice route builder so it can access this route
// and offer features to manipulate the route directly
+ boolean logRoutesAsXml = true;
if (builder instanceof AdviceWithRouteBuilder) {
- ((AdviceWithRouteBuilder) builder).setOriginalRoute(definition);
+ AdviceWithRouteBuilder arb = (AdviceWithRouteBuilder) builder;
+ arb.setOriginalRoute(definition);
+ logRoutesAsXml = arb.isLogRouteAsXml();
}
// configure and prepare the routes from the builder
@@ -161,7 +164,10 @@ public class RouteReifier extends ProcessorReifier<RouteDefinition> {
throw new IllegalArgumentException("You can not advice with error handlers. Remove the error handlers from the route builder.");
}
- String beforeAsXml = ModelHelper.dumpModelAsXml(camelContext, definition);
+ String beforeAsXml = null;
+ if (logRoutesAsXml && log.isInfoEnabled()) {
+ beforeAsXml = ModelHelper.dumpModelAsXml(camelContext, definition);
+ }
// stop and remove this existing route
camelContext.getExtension(Model.class).removeRouteDefinition(definition);
@@ -181,10 +187,14 @@ public class RouteReifier extends ProcessorReifier<RouteDefinition> {
camelContext.getExtension(Model.class).getRouteDefinitions().add(0, merged);
// log the merged route at info level to make it easier to end users to spot any mistakes they may have made
- log.info("AdviceWith route after: {}", merged);
+ if (log.isInfoEnabled()) {
+ log.info("AdviceWith route after: {}", merged);
+ }
- String afterAsXml = ModelHelper.dumpModelAsXml(camelContext, merged);
- log.info("Adviced route before/after as XML:\n{}\n{}", beforeAsXml, afterAsXml);
+ if (logRoutesAsXml && log.isInfoEnabled()) {
+ String afterAsXml = ModelHelper.dumpModelAsXml(camelContext, merged);
+ log.info("Adviced route before/after as XML:\n{}\n{}", beforeAsXml, afterAsXml);
+ }
// If the camel context is started then we start the route
if (camelContext.isStarted()) {