liz3
03/11/2018, 11:32 PMfun main(args: Array<String>) {
System.setOut(SprummlbotOutStream())
System.out.println("Test System.out.println()")
println("Test println")
}
Thats the output:
[12.3.2018 00:26:40 | INFO] Test System.out.println()
Test println
Process finished with exit code 0
SprummlbotOutStream
public class SprummlbotOutStream extends PrintStream {
public SprummlbotOutStream() {
super(System.out);
}
@Override
public void println(String msg) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("d.M.Y HH:mm:ss");
if (!msg.startsWith("["))
msg = " " + msg;
super.println("[" + sdf.format(cal.getTime()) + " | INFO]" + msg);
}
}
My question: why does println use the old stream?
Kotlin pl: 1.2.30
JDK: 1.8.0_162ilya.gorbunov
03/11/2018, 11:43 PMprintln
uses the current stream, it's just that stream does not override println(Object msg)
method overload.liz3
03/11/2018, 11:43 PMilya.gorbunov
03/12/2018, 12:04 AMPrintStream
doesn't seem to be well suited for overriding. Actually you need to override each print*
method, if you want to process/modify the message.