Currently I am using MessageConsole's
, MessageConsoleStream
to write to console.
My question is, Is it possible to do some configuration such that everything I write to output stream is redirected to MessageConsoleStream
.
Example, if I issue the following it should automatically write to the configured console.
System.out.println("txt")
e.printStackTrace()
You can redirect all out
and err
data, System.out.println("txt")
and e.printStackTrace()
are printed to the out
stream while "Unchecked excepctions" are printed to the err
stream.
In this example System.out.println("txt")
would write txt
to the log.txt
file.
OutputStream out = new FileOutputStream("log.txt");
PrintStream stream = new PrintStream(out);
System.setOut(stream);
System.setErr(stream);
In your case you could do something like this:
MessageConsoleStream out = ...;
PrintStream stream = new PrintStream(out);
System.setOut(stream);
System.setErr(stream);