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

commit 07a57445003c5791fff2e81dc7b32e8650183e0e
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Feb 18 16:02:01 2022 +0100

    camel-jbang - Add option to turn off logging
---
 .../apache/camel/dsl/jbang/core/commands/Run.java  | 29 ++++++++++++++++------
 .../camel/dsl/jbang/core/common/RuntimeUtil.java   |  3 +++
 2 files changed, 24 insertions(+), 8 deletions(-)

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 778b90d..0130588 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
@@ -52,17 +52,20 @@ class Run implements Callable<Integer> {
     @Parameters(description = "The Camel file(s) to run", arity = "1")
     private String[] files;
 
-    @Option(names = { "--dep", "--dependency" }, description = "Additional 
dependencies to add to the classpath", arity = "0")
-    private String[] dependencies;
-
     //CHECKSTYLE:OFF
     @Option(names = {"-h", "--help"}, usageHelp = true, description = "Display 
the help and sub-commands")
     private boolean helpRequested;
     //CHECKSTYLE:ON
 
+    @Option(names = { "--dep", "--dependency" }, description = "Additional 
dependencies to add to the classpath", arity = "0")
+    private String[] dependencies;
+
     @Option(names = { "--name" }, defaultValue = "CamelJBang", description = 
"The name of the Camel application")
     private String name;
 
+    @Option(names = { "--logging" }, description = "Can be used to turn of 
logging")
+    private boolean logging = true;
+
     @Option(names = { "--logging-level" }, defaultValue = "info", description 
= "Logging level")
     private String loggingLevel;
 
@@ -133,9 +136,13 @@ class Run implements Callable<Integer> {
         File[] lockFiles = currentDir.listFiles(f -> 
f.getName().endsWith(".camel.lock"));
 
         for (File lockFile : lockFiles) {
-            System.out.println("Removing file " + lockFile);
+            if (logging) {
+                System.out.println("Removing file " + lockFile);
+            }
             if (!lockFile.delete()) {
-                System.err.println("Failed to remove lock file " + lockFile);
+                if (logging) {
+                    System.err.println("Failed to remove lock file " + 
lockFile);
+                }
             }
         }
 
@@ -144,7 +151,11 @@ class Run implements Callable<Integer> {
 
     private int run() throws Exception {
         // configure logging first
-        RuntimeUtil.configureLog(loggingLevel);
+        if (logging) {
+            RuntimeUtil.configureLog(loggingLevel);
+        } else {
+            RuntimeUtil.configureLog("off");
+        }
 
         KameletMain main;
 
@@ -328,8 +339,10 @@ class Run implements Callable<Integer> {
     public File createLockFile() throws IOException {
         File lockFile = File.createTempFile(".run", ".camel.lock", new 
File("."));
 
-        System.out.printf("A new lock file was created, delete the file to 
stop running:%n%s%n",
-                lockFile.getAbsolutePath());
+        if (logging) {
+            System.out.printf("A new lock file was created, delete the file to 
stop running:%n%s%n",
+                    lockFile.getAbsolutePath());
+        }
         lockFile.deleteOnExit();
 
         return lockFile;
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 2494cdc..27c0460 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
@@ -33,6 +33,9 @@ public final class RuntimeUtil {
         level = level.toLowerCase();
 
         switch (level) {
+            case "off":
+                Configurator.setRootLevel(Level.OFF);
+                break;
             case "trace":
                 Configurator.setRootLevel(Level.TRACE);
                 break;

Reply via email to