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 2026/03/02 18:32:44 UTC
(camel) 01/01: CAMEL-23084: camel-jbang - camel infra log - May log duplicate
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch nl
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 31d1a5394f65920263fd23b6d2ea9c967467529f
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Mar 2 19:32:23 2026 +0100
CAMEL-23084: camel-jbang - camel infra log - May log duplicate
---
.../jbang-commands/camel-jbang-infra-log.adoc | 1 +
.../META-INF/camel-jbang-commands-metadata.json | 2 +-
.../dsl/jbang/core/commands/infra/InfraLog.java | 24 +++++++++++-----------
3 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-infra-log.adoc b/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-infra-log.adoc
index 5ad27765daaf..efe73cbe3316 100644
--- a/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-infra-log.adoc
+++ b/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-infra-log.adoc
@@ -20,6 +20,7 @@ camel infra log [options]
|===
| Option | Description | Default | Type
| `--json` | Output in JSON Format | | boolean
+| `--lines` | The number of lines from the end of the log to use as starting offset | 50 | int
| `-h,--help` | Display the help and sub-commands | | boolean
|===
diff --git a/dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json b/dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json
index d2611e13d023..2a04a11bd0ed 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json
+++ b/dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json
@@ -15,7 +15,7 @@
{ "name": "get", "fullName": "get", "description": "Get status of Camel integrations", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.process.CamelStatus", "options": [ { "names": "--watch", "description": "Execute periodically and showing output fullscreen", "javaType": "boolean", "type": "boolean" }, { "names": "-h,--help", "description": "Display the help and sub-commands", "javaType": "boolean", "type": "boolean" } ], "subcommands": [ { "name": "bean", "fullName": "get [...]
{ "name": "harden", "fullName": "harden", "description": "Suggest security hardening for Camel routes using AI\/LLM", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.Harden", "options": [ { "names": "--api-key", "description": "API key for authentication. Also reads OPENAI_API_KEY or LLM_API_KEY env vars", "javaType": "java.lang.String", "type": "string" }, { "names": "--api-type", "description": "API type: 'ollama' or 'openai' (OpenAI-compatible)", "defaultValue": "ollama", [...]
{ "name": "hawtio", "fullName": "hawtio", "description": "Launch Hawtio web console", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.process.Hawtio", "options": [ { "names": "--openUrl", "description": "To automatic open Hawtio web console in the web browser", "defaultValue": "true", "javaType": "boolean", "type": "boolean" }, { "names": "--port", "description": "Port number to use for Hawtio web console (port 8888 by default)", "defaultValue": "8888", "javaType": "int", "t [...]
- { "name": "infra", "fullName": "infra", "description": "List and Run external services for testing and prototyping", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.infra.InfraCommand", "options": [ { "names": "--json", "description": "Output in JSON Format", "javaType": "boolean", "type": "boolean" }, { "names": "-h,--help", "description": "Display the help and sub-commands", "javaType": "boolean", "type": "boolean" } ], "subcommands": [ { "name": "get", "fullName": "infra [...]
+ { "name": "infra", "fullName": "infra", "description": "List and Run external services for testing and prototyping", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.infra.InfraCommand", "options": [ { "names": "--json", "description": "Output in JSON Format", "javaType": "boolean", "type": "boolean" }, { "names": "-h,--help", "description": "Display the help and sub-commands", "javaType": "boolean", "type": "boolean" } ], "subcommands": [ { "name": "get", "fullName": "infra [...]
{ "name": "init", "fullName": "init", "description": "Creates a new Camel integration", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.Init", "options": [ { "names": "--clean-dir,--clean-directory", "description": "Whether to clean directory first (deletes all files in directory)", "javaType": "boolean", "type": "boolean" }, { "names": "--dir,--directory", "description": "Directory relative path where the new Camel integration will be saved", "defaultValue": ".", "javaType" [...]
{ "name": "jolokia", "fullName": "jolokia", "description": "Attach Jolokia JVM Agent to a running Camel integration", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.process.Jolokia", "options": [ { "names": "--port", "description": "To use a specific port number when attaching Jolokia JVM Agent (default a free port is found in range 8778-9999)", "javaType": "int", "type": "integer" }, { "names": "--stop", "description": "Stops the Jolokia JVM Agent in the running Camel inte [...]
{ "name": "log", "fullName": "log", "description": "Tail logs from running Camel integrations", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.action.CamelLogAction", "options": [ { "names": "--find", "description": "Find and highlight matching text (ignore case).", "javaType": "java.lang.String", "type": "string" }, { "names": "--follow", "description": "Keep following and outputting new log lines (press enter to exit).", "defaultValue": "true", "javaType": "boolean", "typ [...]
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/infra/InfraLog.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/infra/InfraLog.java
index 050566dba05e..cbf9f0492243 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/infra/InfraLog.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/infra/InfraLog.java
@@ -41,6 +41,10 @@ public class InfraLog extends InfraBaseCommand {
@CommandLine.Parameters(description = "Service name", arity = "0..2")
private List<String> serviceName;
+ @CommandLine.Option(names = { "--lines" }, defaultValue = "50",
+ description = "The number of lines from the end of the log to use as starting offset")
+ private int logLines = 50;
+
private ExecutorService executorService;
public InfraLog(CamelJBangMain main) {
@@ -109,6 +113,7 @@ public class InfraLog extends InfraBaseCommand {
private void createTailer(File logFile, String alias, List<Future<?>> futures) {
Tailer tailer = Tailer.builder()
.setFile(logFile)
+ .setTailFromEnd(true)
.setTailerListener(new StdoutTailerListener(alias))
.get();
@@ -119,7 +124,7 @@ public class InfraLog extends InfraBaseCommand {
class StdoutTailerListener implements TailerListener {
- private String suffix;
+ private final String suffix;
private Tailer self;
public StdoutTailerListener(String suffix) {
@@ -149,23 +154,18 @@ public class InfraLog extends InfraBaseCommand {
@Override
public void init(Tailer tailer) {
this.self = tailer;
- try (ReversedLinesFileReader fileReader = new ReversedLinesFileReader(tailer.getFile())) {
- StringBuilder sb = new StringBuilder();
- int linesToRead = 50;
- for (int i = 0; i < linesToRead; i++) {
+ try (ReversedLinesFileReader fileReader = ReversedLinesFileReader.builder().setFile(tailer.getFile()).get()) {
+ List<String> lines = new ArrayList<>(logLines);
+ for (int i = 0; i < logLines; i++) {
String line = fileReader.readLine();
if (line == null) {
break;
}
-
- // prepend
- sb.insert(0, "[" + suffix + "] " + line);
+ lines.add(0, line);
}
-
- printer().println(sb.toString());
+ lines.forEach(this::handle);
} catch (IOException e) {
- printer().println("Error collecting logs");
- printer().printErr(e);
+ printer().printErr("Error initializing logs", e);
}
}
}