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

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


The following commit(s) were added to refs/heads/main by this push:
     new 22b137ceda3c CAMEL-24701: camel-jbang - logging.level.root in 
application.properties keeps the CLI log layout and --logging-level wins 
(#26366)
22b137ceda3c is described below

commit 22b137ceda3c662eb37b5b4e04f7279cdc6ae1bb
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Sep 13 16:26:12 2026 +0200

    CAMEL-24701: camel-jbang - logging.level.root in application.properties 
keeps the CLI log layout and --logging-level wins (#26366)
    
    Squash of the 2 commits on fix/CAMEL-24701 (the run-by-run history is on 
bench/after-run).
    
    camel-jbang - logging.level.root in application.properties is the root 
logging level, not a second root logger
    camel-jbang - a logging category from application.properties must not be 
additive, or every line is logged twice
    
    Co-authored-by: Claude Fable 5.1 <[email protected]>
---
 .../apache/camel/dsl/jbang/core/commands/Run.java    | 20 ++++++++++++++++++++
 .../camel/dsl/jbang/core/common/RuntimeUtil.java     | 11 +++++++++++
 2 files changed, 31 insertions(+)

diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
index ea049bba5f11..dc81b39f169d 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
@@ -3000,6 +3000,15 @@ public class Run extends CamelCommand {
         return main;
     }
 
+    private boolean isLoggingLevelFromCommandLine() {
+        try {
+            var parsed = spec != null && spec.commandLine() != null ? 
spec.commandLine().getParseResult() : null;
+            return parsed != null && 
parsed.hasMatchedOption("--logging-level");
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
     private void configureLogging(Path baseDir, Properties profileProperties) 
throws Exception {
         if (loggingOptions.logging) {
             // allow to configure individual logging levels in 
application.properties
@@ -3010,6 +3019,8 @@ public class Run extends CamelCommand {
                     String value = prop.getProperty(key);
                     if (key.startsWith("logging.level.")) {
                         key = key.substring(14);
+                    } else if ("quarkus.log.level".equals(key)) {
+                        key = "root";
                     } else if (key.startsWith("quarkus.log.category.")) {
                         key = key.substring(21);
                         if (key.endsWith(".level")) {
@@ -3019,6 +3030,15 @@ public class Run extends CamelCommand {
                         continue;
                     }
                     key = StringHelper.removeLeadingAndEndingQuotes(key);
+                    if ("root".equalsIgnoreCase(key)) {
+                        // logging.level.root (Spring Boot style) and 
quarkus.log.level are the root logging level,
+                        // not a logger category (log4j allows one root logger 
only), so use it as the level unless
+                        // --logging-level was given explicitly
+                        if (!isLoggingLevelFromCommandLine()) {
+                            loggingOptions.loggingLevel = value;
+                        }
+                        continue;
+                    }
                     String line = key + "=" + value;
                     String line2 = key + " = " + value;
                     if (!loggingOptions.loggingCategory.contains(line)
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/RuntimeUtil.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/RuntimeUtil.java
index 8ccd3cdcef6b..b2c8fbe3b25e 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/RuntimeUtil.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/RuntimeUtil.java
@@ -83,9 +83,20 @@ public final class RuntimeUtil {
                     String prefix = "custom" + i++;
                     String catName = StringHelper.before(lc, "=", "").trim();
                     String catLevel = StringHelper.after(lc, "=", "").trim();
+                    if ("root".equalsIgnoreCase(catName)) {
+                        // log4j allows one root logger only, which the 
template already defines: a root category is
+                        // the root logging level
+                        if (!catLevel.isEmpty()) {
+                            level = catLevel;
+                        }
+                        continue;
+                    }
                     if (!catName.isEmpty() && !catLevel.isEmpty()) {
                         sj.add("logger." + prefix + ".name=" + catName);
                         sj.add("logger." + prefix + ".level=" + catLevel);
+                        // the category gets the same appenders as the root 
logger, so it must not also pass its
+                        // events up to the root, or every line is printed 
twice (CAMEL-24701)
+                        sj.add("logger." + prefix + ".additivity=false");
                         if (!export && !script) {
                             sj.add("logger." + prefix + 
".appenderRef.$1.ref=out");
                         }

Reply via email to