Two OutputStream's instead of one?
-
22-09-2019 - |
Question
I am dealing with a commerical Java API that exposes only the following logging configuration:
cplex.setOut(OutputStream arg0);
I would like to have logging to two streams: a file and the console. Is it possible?
Solution
Write your own OutputStream implementation which delegates calls to the write
methods to two wrapped OutputStreams, one for the console and one for the file.
OTHER TIPS
i believe it is.
I would user the apache commons io lib.
For example
FileOutputStream fos = ...;
TeeOutputStream brancher = TeeOutputStream(fos, System.out);
cplex.setOut(brancher);
You can use a TeeOutputStream
from the Apache Commons IO library.
Easy:
cplex.setOut(new OutputStream() {
public void write(int b) throws IOException {
outputStream1.write(b);
outputStream2.write(b);
}
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow