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 2024/02/14 05:59:09 UTC

(camel) branch logname created (now a2eb844d5d8)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch logname
in repository https://gitbox.apache.org/repos/asf/camel.git


      at a2eb844d5d8 CAMEL-20418: camel-core - Log EIP should only use source line:name if enabled

This branch includes the following new commits:

     new a2eb844d5d8 CAMEL-20418: camel-core - Log EIP should only use source line:name if enabled

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(camel) 01/01: CAMEL-20418: camel-core - Log EIP should only use source line:name if enabled

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch logname
in repository https://gitbox.apache.org/repos/asf/camel.git

commit a2eb844d5d8d4e02324b91f5fb3d1485d2258771
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Feb 14 06:58:57 2024 +0100

    CAMEL-20418: camel-core - Log EIP should only use source line:name if enabled
---
 .../src/main/docs/modules/eips/pages/log-eip.adoc             | 11 +++++++----
 .../src/main/java/org/apache/camel/reifier/LogReifier.java    |  7 ++++++-
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/core/camel-core-engine/src/main/docs/modules/eips/pages/log-eip.adoc b/core/camel-core-engine/src/main/docs/modules/eips/pages/log-eip.adoc
index eb39dd5dfe4..7936d4e8f4b 100644
--- a/core/camel-core-engine/src/main/docs/modules/eips/pages/log-eip.adoc
+++ b/core/camel-core-engine/src/main/docs/modules/eips/pages/log-eip.adoc
@@ -92,7 +92,7 @@ from("file://target/files")
     .to("bean:foo");
 ----
 
-In Spring DSL it is also easy to use log DSL as shown below:
+In XML DSL it is also easy to use log DSL as shown below:
 [source,xml]
 ----
 <route id="foo">
@@ -131,10 +131,10 @@ It is possible to reference an existing logger instance. For example:
 
 === Configuring logging name
 
-The log message will be logged at `INFO` level using the route id as the logger name.
-So for example if you have not assigned an id to the route, then Camel will use `route-1`, `route-2` as the logger name.
+The log message will be logged at `INFO` level using the route id as the logger name (or source name:line if source location is enabled, see TIP below).
+So for example, if you have not assigned an id to the route, then Camel will use `route-1`, `route-2` as the logger name.
 
-For example to use "fooRoute" as the route id, you can do:
+To use "fooRoute" as the route id, you can do:
 
 [source,java]
 ----
@@ -154,6 +154,9 @@ And in XML:
 </route>
 ----
 
+TIP: If you enable `sourceLocationEnabled=true` on `CamelContext` then Camel will use source file:line as logger name,
+instead of the route id. This is for example what `camel-jbang` do, to make it easy to see where in the source code the log is located.
+
 ==== Using custom logger from the Registry
 
 If the Log EIP has not been configured with a specific logger to use,
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/LogReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/LogReifier.java
index a1744b48135..93dd053d2bb 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/LogReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/LogReifier.java
@@ -76,7 +76,12 @@ public class LogReifier extends ProcessorReifier<LogDefinition> {
                 }
             }
             if (name == null) {
-                name = getLineNumberLoggerName(definition);
+                if (camelContext.isSourceLocationEnabled()) {
+                    name = getLineNumberLoggerName(definition);
+                    if (name != null) {
+                        LOG.debug("LogName is not configured, using source location as logName: {}", name);
+                    }
+                }
                 if (name == null) {
                     name = route.getRouteId();
                     LOG.debug("LogName is not configured, using route id as logName: {}", name);