Repository: camel
Updated Branches:
  refs/heads/master fc0eb8c57 -> b7cd003fb


CAMEL-9715: Log EIP - Allow to configure the log name globally


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b7cd003f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b7cd003f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b7cd003f

Branch: refs/heads/master
Commit: b7cd003fb13e77d230c679ca6f0ad9c78272444b
Parents: fc0eb8c
Author: Claus Ibsen <davscl...@apache.org>
Authored: Wed Mar 16 09:57:12 2016 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Wed Mar 16 09:57:12 2016 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/camel/Exchange.java    |  1 +
 .../org/apache/camel/model/LogDefinition.java   |  9 +++++-
 .../camel/processor/LogGlobalLogNameTest.java   | 33 ++++++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b7cd003f/camel-core/src/main/java/org/apache/camel/Exchange.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/Exchange.java 
b/camel-core/src/main/java/org/apache/camel/Exchange.java
index 1780b65..80b3b92 100644
--- a/camel-core/src/main/java/org/apache/camel/Exchange.java
+++ b/camel-core/src/main/java/org/apache/camel/Exchange.java
@@ -159,6 +159,7 @@ public interface Exchange {
     String LANGUAGE_SCRIPT          = "CamelLanguageScript";
     String LOG_DEBUG_BODY_MAX_CHARS = "CamelLogDebugBodyMaxChars";
     String LOG_DEBUG_BODY_STREAMS   = "CamelLogDebugStreams";
+    String LOG_EIP_NAME             = "CamelLogEipName";
     String LOOP_INDEX               = "CamelLoopIndex";
     String LOOP_SIZE                = "CamelLoopSize";
 

http://git-wip-us.apache.org/repos/asf/camel/blob/b7cd003f/camel-core/src/main/java/org/apache/camel/model/LogDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/LogDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/LogDefinition.java
index 84060e4..299ffaa 100644
--- a/camel-core/src/main/java/org/apache/camel/model/LogDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/LogDefinition.java
@@ -23,6 +23,7 @@ import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlTransient;
 
+import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.LoggingLevel;
 import org.apache.camel.Processor;
@@ -106,8 +107,14 @@ public class LogDefinition extends 
NoOutputDefinition<LogDefinition> {
         if (logger == null) {
             String name = getLogName();
             if (name == null) {
+                name = 
routeContext.getCamelContext().getProperty(Exchange.LOG_EIP_NAME);
+                if (name != null) {
+                    LOG.debug("Using logName from CamelContext properties: 
{}", name);
+                }
+            }
+            if (name == null) {
                 name = routeContext.getRoute().getId();
-                LOG.debug("The LogName is null. Falling back to create logger 
by using the route id {}.", name);
+                LOG.debug("LogName is not configured, using route id as 
logName: {}", name);
             }
             logger = LoggerFactory.getLogger(name);
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/b7cd003f/camel-core/src/test/java/org/apache/camel/processor/LogGlobalLogNameTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/processor/LogGlobalLogNameTest.java 
b/camel-core/src/test/java/org/apache/camel/processor/LogGlobalLogNameTest.java
new file mode 100644
index 0000000..cad1eff
--- /dev/null
+++ 
b/camel-core/src/test/java/org/apache/camel/processor/LogGlobalLogNameTest.java
@@ -0,0 +1,33 @@
+/**
+ * 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.CamelContext;
+import org.apache.camel.Exchange;
+
+/**
+ * @version 
+ */
+public class LogGlobalLogNameTest extends LogProcessorTest {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        context.getProperties().put(Exchange.LOG_EIP_NAME, "com.foo.myapp");
+        return context;
+    }
+}

Reply via email to