1

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?

4 Answers 4

11

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);
0
2

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.

1
  • I redirected the logging to log4j from there and it works fine.
    – Gerard
    Commented Apr 1, 2010 at 8:40
2

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

0

Easy:

cplex.setOut(new OutputStream() {

    public void write(int b) throws IOException {
        outputStream1.write(b);
        outputStream2.write(b);
    }
});

Not the answer you're looking for? Browse other questions tagged or ask your own question.