I’m trying to intercept System.out and System.err, but maintain the ability to write to the original streams directly when necessary.
PrintStream ps = System.out;
System.setOut(new MyMagicPrintStream());
ps.println("foo");
Unfortunately, the details of the System class’ implementation means that in my example, “foo” gets sent to MyMagicPrintStream instead of the real stdout.
Does anyone know how to get references to the real/original OutputStreams?
Thanks.
PS: This will otherwise result in a StackOverflowError <– for SEO.
try this: