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 | 44 |
1 files changed, 20 insertions, 24 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 8e4b9aea9b8..3532dac09f5 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 @@ -62,34 +62,30 @@ class LogReader { double fromSeconds = from.getEpochSecond() + from.getNano() / 1e9; double toSeconds = to.getEpochSecond() + to.getNano() / 1e9; BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out)); - try { - for (List<Path> logs : getMatchingFiles(from, to)) { - List<LogLineIterator> logLineIterators = new ArrayList<>(); - try { - // Logs in each sub-list contain entries covering the same time interval, so do a merge sort while reading - for (Path log : logs) - logLineIterators.add(new LogLineIterator(log, fromSeconds, toSeconds, hostname)); - - Iterator<LineWithTimestamp> lines = Iterators.mergeSorted(logLineIterators, - Comparator.comparingDouble(LineWithTimestamp::timestamp)); - while (lines.hasNext()) { - writer.write(lines.next().line()); - writer.newLine(); - } - } - catch (IOException e) { - throw new UncheckedIOException(e); + for (List<Path> logs : getMatchingFiles(from, to)) { + List<LogLineIterator> logLineIterators = new ArrayList<>(); + try { + // Logs in each sub-list contain entries covering the same time interval, so do a merge sort while reading + for (Path log : logs) + logLineIterators.add(new LogLineIterator(log, fromSeconds, toSeconds, hostname)); + + Iterator<LineWithTimestamp> lines = Iterators.mergeSorted(logLineIterators, + Comparator.comparingDouble(LineWithTimestamp::timestamp)); + while (lines.hasNext()) { + writer.write(lines.next().line()); + writer.newLine(); } - finally { - for (LogLineIterator ll : logLineIterators) { - try { ll.close(); } catch (IOException ignored) { } - } + } + catch (IOException e) { + throw new UncheckedIOException(e); + } + finally { + for (LogLineIterator ll : logLineIterators) { + try { ll.close(); } catch (IOException ignored) { } } + Exceptions.uncheck(writer::flush); } } - finally { - Exceptions.uncheck(writer::flush); - } } private static class LogLineIterator implements Iterator<LineWithTimestamp>, AutoCloseable { |