aboutsummaryrefslogtreecommitdiff
path: root/src/cz/crcs/ectester/reader/output/OutputLogger.java
diff options
context:
space:
mode:
authorJ08nY2017-10-14 01:14:07 +0200
committerJ08nY2017-10-15 00:19:18 +0200
commit114c3378e323b954bfd8c0470e489c9615978d58 (patch)
tree46281a9f45c91bdad518e7e21e5edff099b96c01 /src/cz/crcs/ectester/reader/output/OutputLogger.java
parent88f829e238097343a044f437c2d4cfeb8b6cfdff (diff)
downloadECTester-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.java60
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();
+ }
+}