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 b99d3effb74 CAMEL-19033: camel-jbang - get trace -> trace b99d3effb74 is described below commit b99d3effb74f022465277dca7d805992c3cbdaa1 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Feb 16 09:13:19 2023 +0100 CAMEL-19033: camel-jbang - get trace -> trace --- .../jbang/core/commands/action/CamelLogAction.java | 28 +++++++++++++--------- .../core/commands/action/CamelTraceAction.java | 19 ++++++++++----- 2 files changed, 30 insertions(+), 17 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 4eee515eb80..b622f6e5213 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 @@ -70,9 +70,9 @@ public class CamelLogAction extends ActionBaseCommand { description = "Print prefix with running Camel integration name.") boolean prefix = true; - @CommandLine.Option(names = { "--tail" }, - description = "The number of lines from the end of the logs to show. Defaults to showing all logs.") - int tail; + @CommandLine.Option(names = { "--tail" }, defaultValue = "-1", + description = "The number of lines from the end of the logs to show. Use -1 to read from the beginning. Use 0 to read only new lines. Defaults to showing all logs from beginning.") + int tail = -1; @CommandLine.Option(names = { "--since" }, description = "Return logs newer than a relative duration like 5s, 2m, or 1h. The value is in seconds if no unit specified.") @@ -131,10 +131,11 @@ public class CamelLogAction extends ActionBaseCommand { } limit = new Date(System.currentTimeMillis() - millis); } - - // dump existing log lines - tailLogFiles(rows, tail, limit); - dumpLogFiles(rows, tail); + if (tail != 0) { + // dump existing log lines + tailLogFiles(rows, tail, limit); + dumpLogFiles(rows, tail); + } } if (follow) { @@ -218,9 +219,14 @@ public class CamelLogAction extends ActionBaseCommand { for (Row row : rows.values()) { if (row.reader == null) { - File log = logFile(row.pid); - if (log.exists()) { - row.reader = new LineNumberReader(new FileReader(log)); + File file = logFile(row.pid); + if (file.exists()) { + row.reader = new LineNumberReader(new FileReader(file)); + if (tail == 0) { + // only read new lines so forward to end of reader + long size = file.length(); + row.reader.skip(size); + } } } if (row.reader != null) { @@ -380,7 +386,7 @@ public class CamelLogAction extends ActionBaseCommand { if (log.exists()) { row.reader = new LineNumberReader(new FileReader(log)); String line; - if (tail == 0) { + if (tail <= 0) { row.fifo = new ArrayDeque<>(); } else { row.fifo = new ArrayBlockingQueue<>(tail); diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelTraceAction.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelTraceAction.java index 6965a378dd2..e3ffe32f75b 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelTraceAction.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/action/CamelTraceAction.java @@ -84,9 +84,9 @@ public class CamelTraceAction extends ActionBaseCommand { description = "Detail level of tracing. 0 = Created+Completed. 1=All events on 1st level, 2=All events on 1st+2nd level, and so on. 9 = all events on every level.") int level; - @CommandLine.Option(names = { "--tail" }, - description = "The number of traces from the end of the trace to show. Defaults to showing all traces.") - int tail; + @CommandLine.Option(names = { "--tail" }, defaultValue = "-1", + description = "The number of traces from the end of the trace to show. Use -1 to read from the beginning. Use 0 to read only new lines. Defaults to showing all traces from beginning.") + int tail = -1; @CommandLine.Option(names = { "--since" }, description = "Return traces newer than a relative duration like 5s, 2m, or 1h. The value is in seconds if no unit specified.") @@ -171,8 +171,10 @@ public class CamelTraceAction extends ActionBaseCommand { limit = new Date(System.currentTimeMillis() - millis); } // dump existing traces - tailTraceFiles(pids, tail); - dumpTraceFiles(pids, tail, limit); + if (tail != 0) { + tailTraceFiles(pids, tail); + dumpTraceFiles(pids, tail, limit); + } } if (follow) { @@ -212,7 +214,7 @@ public class CamelTraceAction extends ActionBaseCommand { if (file.exists()) { pid.reader = new LineNumberReader(new FileReader(file)); String line; - if (tail == 0) { + if (tail <= 0) { pid.fifo = new ArrayDeque<>(); } else { pid.fifo = new ArrayBlockingQueue<>(tail); @@ -282,6 +284,11 @@ public class CamelTraceAction extends ActionBaseCommand { File file = getTraceFile(pid.pid); if (file.exists()) { pid.reader = new LineNumberReader(new FileReader(file)); + if (tail == 0) { + // only read new lines so forward to end of reader + long size = file.length(); + pid.reader.skip(size); + } } } if (pid.reader != null) {