diff options
| author | J08nY | 2017-10-14 01:14:07 +0200 |
|---|---|---|
| committer | J08nY | 2017-10-15 00:19:18 +0200 |
| commit | 114c3378e323b954bfd8c0470e489c9615978d58 (patch) | |
| tree | 46281a9f45c91bdad518e7e21e5edff099b96c01 /src/cz/crcs/ectester/reader/output/OutputLogger.java | |
| parent | 88f829e238097343a044f437c2d4cfeb8b6cfdff (diff) | |
| download | ECTester-114c3378e323b954bfd8c0470e489c9615978d58.tar.gz ECTester-114c3378e323b954bfd8c0470e489c9615978d58.tar.zst ECTester-114c3378e323b954bfd8c0470e489c9615978d58.zip | |
Refactor response and test outputing into separate writers.
This is done to provide multiple output formats, one which logs
tests to console in simple human readable format and others.
Diffstat (limited to 'src/cz/crcs/ectester/reader/output/OutputLogger.java')
| -rw-r--r-- | src/cz/crcs/ectester/reader/output/OutputLogger.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/cz/crcs/ectester/reader/output/OutputLogger.java b/src/cz/crcs/ectester/reader/output/OutputLogger.java new file mode 100644 index 0000000..bf47a1f --- /dev/null +++ b/src/cz/crcs/ectester/reader/output/OutputLogger.java @@ -0,0 +1,60 @@ +package cz.crcs.ectester.reader.output; + +import java.io.*; +import java.util.LinkedList; +import java.util.List; + +/** + * @author Petr Svenda petr@svenda.com + * @author Jan Jancar johny@neuromancer.sk + */ +public class OutputLogger { + private OutputStream out; + private PrintStream print; + + public OutputLogger(boolean systemOut, String... filePaths) throws IOException { + List<OutputStream> streams = new LinkedList<>(); + for (String filePath : filePaths) { + if (filePath != null) { + streams.add(new FileOutputStream(filePath)); + } + } + if (systemOut) { + streams.add(System.out); + } + this.out = new TeeOutputStream(streams.toArray(new OutputStream[0])); + this.print = new PrintStream(this.out); + } + + public OutputLogger(String filePath) throws IOException { + this(true, filePath); + } + + public OutputStream getOutputStream() { + return this.out; + } + + public PrintStream getPrintStream() { + return this.print; + } + + public void println() { + print.println(); + } + + public void println(String logLine) { + print.println(logLine); + } + + public void print(String logLine) { + print.print(logLine); + } + + public void flush() { + print.flush(); + } + + public void close() { + print.close(); + } +} |
