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 2025/04/28 07:56:36 UTC
(camel) branch main updated: camel-jbang: Make camel log a bit more roboust when aligning timestamps
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 f038b3d8f99 camel-jbang: Make camel log a bit more roboust when aligning timestamps
f038b3d8f99 is described below
commit f038b3d8f99898c7fdb47b3c9a2e152cd1ac3028
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Apr 28 09:56:19 2025 +0200
camel-jbang: Make camel log a bit more roboust when aligning timestamps
---
.../jbang/core/commands/action/CamelLogAction.java | 26 +++++++++++++++-------
1 file changed, 18 insertions(+), 8 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 e390af4cf48..a88e4b5c47a 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
@@ -57,6 +57,7 @@ public class CamelLogAction extends ActionBaseCommand {
private static final int NAME_MIN_WIDTH = 10;
private static final String TIMESTAMP_MAIN = "yyyy-MM-dd HH:mm:ss.SSS";
+ private static final String TIMESTAMP_SB = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
private CommandHelper.ReadConsoleTask waitUserTask;
@@ -489,15 +490,24 @@ public class CamelLogAction extends ActionBaseCommand {
// 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) {
- int pos1 = dot + 3; // skip these 6 chars
- int pos2 = dot + 9;
- ts = ts.substring(0, pos1) + ts.substring(pos2);
+ SimpleDateFormat sdf = new SimpleDateFormat(TIMESTAMP_SB);
+ try {
+ // the log can be in color or not so we need to unescape always
+ sdf.parse(unescapeAnsi(ts));
+ int dot = ts.indexOf('.');
+ if (dot != -1) {
+ int pos1 = dot + 3; // skip millis and timezone
+ int pos2 = dot + 9;
+ if (pos2 < ts.length()) {
+ ts = ts.substring(0, pos1) + ts.substring(pos2);
+ String after = StringHelper.after(line, " ");
+ ts = ts.replace('T', ' ');
+ return ts + " " + after;
+ }
+ }
+ } catch (Exception e) {
+ // ignore
}
- String after = StringHelper.after(line, " ");
- return ts + " " + after;
}
return line;
}