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 4a92560bcd0 camel-jbang - Make camel log read spring boot logs
4a92560bcd0 is described below

commit 4a92560bcd0971b4dd7bf2a91a44729c0d77cdf6
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Apr 29 15:43:45 2024 +0200

    camel-jbang - Make camel log read spring boot logs
---
 .../jbang/core/commands/action/CamelLogAction.java | 24 +++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

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 2310d30959f..7a2a518e82e 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
@@ -54,6 +54,8 @@ public class CamelLogAction extends ActionBaseCommand {
     private static final int NAME_MAX_WIDTH = 25;
     private static final int NAME_MIN_WIDTH = 10;
 
+    private static final String TIMESTAMP_MAIN = "yyyy-MM-dd HH:mm:ss.SSS";
+
     public static class PrefixCompletionCandidates implements Iterable<String> 
{
 
         public PrefixCompletionCandidates() {
@@ -249,6 +251,7 @@ public class CamelLogAction extends ActionBaseCommand {
                     try {
                         line = row.reader.readLine();
                         if (line != null) {
+                            line = alignTimestamp(line);
                             boolean valid = true;
                             if (grep != null) {
                                 valid = isValidGrep(line);
@@ -290,7 +293,7 @@ public class CamelLogAction extends ActionBaseCommand {
         // only sort if there are multiple Camels running
         if (names.size() > 1) {
             // sort lines
-            final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd 
HH:mm:ss.SSS");
+            final SimpleDateFormat sdf = new SimpleDateFormat(TIMESTAMP_MAIN);
             lines.sort((l1, l2) -> {
                 l1 = unescapeAnsi(l1);
                 l2 = unescapeAnsi(l2);
@@ -420,6 +423,7 @@ public class CamelLogAction extends ActionBaseCommand {
                 do {
                     line = row.reader.readLine();
                     if (line != null) {
+                        line = alignTimestamp(line);
                         boolean valid = isValidSince(limit, line);
                         if (valid && grep != null) {
                             valid = isValidGrep(line);
@@ -435,6 +439,21 @@ public class CamelLogAction extends ActionBaseCommand {
         }
     }
 
+    private String alignTimestamp(String line) {
+        // if using spring boot then adjust the timestamp to uniform 
camel-main style
+        String ts = StringHelper.before(line, "  ");
+        if (ts != null && ts.contains("T")) {
+            ts = ts.replace('T', ' ');
+            int dot = ts.indexOf('.');
+            if (dot != -1) {
+                ts = ts.substring(0, dot + 4);
+            }
+            String after = StringHelper.after(line, "  ");
+            return ts + "  " + after;
+        }
+        return line;
+    }
+
     private boolean isValidSince(Date limit, String line) {
         if (limit == null) {
             return true;
@@ -443,7 +462,7 @@ public class CamelLogAction extends ActionBaseCommand {
         line = unescapeAnsi(line);
         String ts = StringHelper.before(line, "  ");
 
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+        SimpleDateFormat sdf = new SimpleDateFormat(TIMESTAMP_MAIN);
         try {
             Date row = sdf.parse(ts);
             return row.compareTo(limit) >= 0;
@@ -498,7 +517,6 @@ public class CamelLogAction extends ActionBaseCommand {
         String name;
         Queue<String> fifo;
         LineNumberReader reader;
-
     }
 
 }

Reply via email to