Class LoggingPrintStream

java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.io.PrintStream
org.glassfish.main.jul.handler.LoggingPrintStream
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class LoggingPrintStream extends PrintStream
LoggingPrintStream has it's own LoggingOutputStream. Once it is set as the System.out or System.err, all outputs to these PrintStreams will end up in LoggingOutputStream which will log these on a flush.

This simple behaviour has a negative side effect that stack traces are logged with each line being a new log record. The reason for above is that Throwable.printStackTrace(PrintStream) converts each line into a separate println, causing a flush at the end of each.

One option that was thought of to smooth this over was to see if the caller of println is Throwable.[some set of methods]. Unfortunately, there are others who interpose on System.out and err (like jasper) which makes that check untenable. Hence the logic currently used is to see if there is a println(Throwable) and create a standard log record of it and then prevent subsequent printline calls done by the Throwable.printStackTrace(PrintStream) method. This is possible because Throwable locks the stream to avoid collisions.