Re: how to read back the lines printed out to the console?
Wow. Thank you so much. I greatly appreciate your effort for putting
up such complete and nicely formatted code, including testing code.
Thank you very very much.
Like Patricia said, I am almost there. Based on your code, my class
ends up to be:
class TeeOutputStream extends OutputStream
{
private final OutputStream os1;
// private final OutputStream os2;
private final Logger _logger; //the class of Logger is our own
class
public TeeOutputStream(final OutputStream os1, final Logger log)
{
this.os1 = os1;
// this.os2 = os2;
this._logger = log;
}
@Override
public void write(final byte[] b) throws IOException
{
os1.write(b);
// os2.write(b);
this._logger.log(Logger.INFO, new String(b));
}
@Override
public void write(final byte[] b, final int off, final int len)
throws IOException
{
os1.write(b, off, len);
// os2.write(b, off, len);
this._logger.log(Logger.INFO, new String(b, off, len));
}
@Override
public void write(final int b) throws IOException
{
os1.write(b);
// os2.write(b);
this._logger.log(Logger.INFO, String.valueOf((char)b));
}
@Override
public void flush() throws IOException
{
os1.flush();
// os2.flush();
}
@Override
public void close() throws IOException
{
os1.close();
this._logger.close();
}
}
At the place of calling this class,
final TeeOutputStream teeOutputStream = new
TeeOutputStream(System.out, logger);
System.setOut(new PrintStream(teeOutputStream));
Since now, all System.out.println(..) message is shown on the console
progressively when the program running and be saved into a file at the
end by writing out our logger object to a xml file.
Thank you again for all the help.