Perhaps the subsystem makes its copy of the values, and you are too late when switching. Try to do this first in your core.
EDIT
OK - I completely missed your idiom. I think you should not use this inner class. You must define an instance of PrintStream in OutputStream that creates a new log entry on each "\ n". The way you do this now misses a lot of the ability to "print" your instance.
package de.mit.stackoverflow; import java.io.IOException; import java.io.OutputStream; public class LogOutputStream extends OutputStream { private StringBuilder sb = new StringBuilder(); @Override public void write(int b) throws IOException { if (b == '\n') { log(sb.toString()); sb.setLength(0); } else { sb.append((char) b); } } }
package de.mit.stackoverflow; import java.io.IOException; import java.io.OutputStream; public class LogOutputStream extends OutputStream { private StringBuilder sb = new StringBuilder(); @Override public void write(int b) throws IOException { if (b == '\n') { log(sb.toString()); sb.setLength(0); } else { sb.append((char) b); } } }
and then do
OutputStream os = new LogOutputStream(); PrintStream ps = new PrintStream(os); System.setOut(ps);
Perhaps you still want to include a link to the previous thread - on the left as an exercise :-)
mtraut
source share