From 6fa5c6604b35f38265dc57326bbd35f66b2d705e Mon Sep 17 00:00:00 2001 From: Christopher Zell Date: Sun, 20 Aug 2023 22:02:56 +0200 Subject: [PATCH] feat: add from-to position parameters --- .../java/io/zell/zdb/LogPrintCommand.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/cli/src/main/java/io/zell/zdb/LogPrintCommand.java b/cli/src/main/java/io/zell/zdb/LogPrintCommand.java index cbbf0c24..241c70f8 100644 --- a/cli/src/main/java/io/zell/zdb/LogPrintCommand.java +++ b/cli/src/main/java/io/zell/zdb/LogPrintCommand.java @@ -15,6 +15,7 @@ */ package io.zell.zdb; +import io.zell.zdb.log.ApplicationRecord; import io.zell.zdb.log.LogContentReader; import java.nio.file.Path; import java.util.concurrent.Callable; @@ -40,6 +41,18 @@ public enum Format { defaultValue = "JSON") private Format format; + @Option( + names = {"--from", "--fromPosition"}, + description = "Print's the complete log from the given position.", + defaultValue = "0") + private long fromPosition; + + @Option( + names = {"--to", "--toPosition"}, + description = "Print's the complete log to the given position.", + defaultValue = Long.MAX_VALUE + "") + private long toPosition; + @Override public Integer call() { final Path partitionPath = spec.findOption("-p").getValue(); @@ -50,8 +63,14 @@ public Integer call() { System.out.println(logContent.asDotFile()); } else { System.out.println("["); - for (LogContentReader it = logContentReader; it.hasNext(); ) { - var record = it.next(); + logContentReader.seekToPosition(fromPosition); + while (logContentReader.hasNext()) { + final var record = logContentReader.next(); + if (record instanceof ApplicationRecord engineRecord) { + if (engineRecord.getLowestPosition() > toPosition) { + break; + } + } System.out.println(record); if (logContentReader.hasNext()) { System.out.print(",");