blob: 09b8f734a9a31df500deeca7ed9bdb4c8d75e0a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
package cz.crcs.ectester.common.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();
}
}
|