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 58d8d74e8be CAMEL-21170: camel-jbang - Add camel log --startup to only 
show startup logs
58d8d74e8be is described below

commit 58d8d74e8beab6e8d8333b4bf1d0f12716c0b630
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Wed Sep 4 16:13:41 2024 +0200

    CAMEL-21170: camel-jbang - Add camel log --startup to only show startup logs
---
 .../jbang/core/commands/action/CamelLogAction.java | 33 +++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelLogAction.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelLogAction.java
index 694ee048d79..5a84377eb33 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelLogAction.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelLogAction.java
@@ -81,6 +81,10 @@ public class CamelLogAction extends ActionBaseCommand {
                         description = "Keep following and outputting new log 
lines (use ctrl + c to exit).")
     boolean follow = true;
 
+    @CommandLine.Option(names = { "--startup" }, defaultValue = "false",
+                        description = "Only shows logs from the starting phase 
to make it quick to look at how Camel was started.")
+    boolean startup;
+
     @CommandLine.Option(names = { "--prefix" }, defaultValue = "auto", 
completionCandidates = PrefixCompletionCandidates.class,
                         description = "Print prefix with running Camel 
integration name. auto=only prefix when running multiple integrations. 
true=always prefix. false=prefix off.")
     String prefix = "auto";
@@ -147,7 +151,12 @@ public class CamelLogAction extends ActionBaseCommand {
                 }
                 limit = new Date(System.currentTimeMillis() - millis);
             }
-            if (tail != 0) {
+            if (startup) {
+                follow = false;
+                // only log startup logs until Camel was started
+                tailStartupLogFiles(rows);
+                dumpLogFiles(rows, 0);
+            } else if (tail != 0) {
                 // dump existing log lines
                 tailLogFiles(rows, tail, limit);
                 dumpLogFiles(rows, tail);
@@ -414,6 +423,28 @@ public class CamelLogAction extends ActionBaseCommand {
         return new File(CommandLineHelper.getCamelDir(), name);
     }
 
+    private void tailStartupLogFiles(Map<Long, Row> rows) throws Exception {
+        for (Row row : rows.values()) {
+            File log = logFile(row.pid);
+            if (log.exists()) {
+                row.fifo = new ArrayDeque<>();
+                row.reader = new LineNumberReader(new FileReader(log));
+                String line;
+                do {
+                    line = row.reader.readLine();
+                    if (line != null) {
+                        row.fifo.offer(line);
+                        boolean found = line.contains("AbstractCamelContext") 
&& line.contains("Apache Camel ")
+                                && line.contains(" started in ") && 
line.contains("(build:");
+                        if (found) {
+                            line = null;
+                        }
+                    }
+                } while (line != null);
+            }
+        }
+    }
+
     private void tailLogFiles(Map<Long, Row> rows, int tail, Date limit) 
throws Exception {
         for (Row row : rows.values()) {
             File log = logFile(row.pid);

Reply via email to