diff options
Diffstat (limited to 'container-core/src/main/java/com/yahoo/container/handler/LogReader.java')
-rw-r--r-- | container-core/src/main/java/com/yahoo/container/handler/LogReader.java | 41 |
1 files changed, 13 insertions, 28 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/handler/LogReader.java b/container-core/src/main/java/com/yahoo/container/handler/LogReader.java index 9ac40158e07..2483f2497d0 100644 --- a/container-core/src/main/java/com/yahoo/container/handler/LogReader.java +++ b/container-core/src/main/java/com/yahoo/container/handler/LogReader.java @@ -7,52 +7,37 @@ import javax.xml.bind.DatatypeConverter; import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.util.Arrays; -import java.util.Comparator; public class LogReader { - int numberOfLogs; + long earliestLogThreshold; + long latestLogThreshold; - public LogReader() { - this.numberOfLogs = -1; - } - - public LogReader(int numberOfLogs) { - this.numberOfLogs = numberOfLogs; + public LogReader(long earliestLogThreshold, long latestLogThreshold) { + this.earliestLogThreshold = earliestLogThreshold; + this.latestLogThreshold = latestLogThreshold; } protected JSONObject readLogs(String logDirectory) throws IOException, JSONException { JSONObject json = new JSONObject(); File root = new File(logDirectory); - traverse_folder(root, json); + traverse_folder(root, json, ""); return json; } - private void traverse_folder(File root, JSONObject json) throws IOException, JSONException { + private void traverse_folder(File root, JSONObject json, String filename) throws IOException, JSONException { File[] files = root.listFiles(); - Arrays.sort(files,new Comparator<File>(){ - public int compare(File f1, File f2) - { - return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified()); - } }); - Arrays.sort(files, Comparator.reverseOrder()); for(File child : files) { - if (numberOfLogs == 0) return; + File temp = child; JSONObject childJson = new JSONObject(); - if(child.isFile()) { - json.put(child.getName(), DatatypeConverter.printBase64Binary(Files.readAllBytes(child.toPath()))); - decrementLogNumber(); + long logTime = child.lastModified(); + if(child.isFile() && earliestLogThreshold < logTime && logTime < latestLogThreshold) { + json.put(filename + child.getName(), DatatypeConverter.printBase64Binary(Files.readAllBytes(child.toPath()))); } - else { - json.put(child.getName(), childJson); - traverse_folder(child, childJson); + else if (!child.isFile()){ + traverse_folder(child, json, filename + child.getName() + "-"); } } } - private void decrementLogNumber() { - numberOfLogs -= 1; - } - } |