views:

67

answers:

3

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?

+3  A: 

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.

matt b
I redirected the logging to log4j from there and it works fine.
Gerard
+2  A: 

You can use a TeeOutputStream from the Apache Commons IO library.

Joachim Sauer
+10  A: 

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);
Paul
+1 cool this is nice!
Karussell