private static void log ( PrintStream out , String prefix , String message , Throwable t ) { final StringBuilder linePrefixBuilder = new StringBuilder ( ) ; synchronized ( fmt ) { linePrefixBuilder . append ( fmt . format ( new Date ( ) ) ) ; } linePrefixBuilder . append ( prefix ) ; linePrefixBuilder . append ( " [" ) ; linePrefixBuilder . append ( Thread . currentThread ( ) . getName ( ) ) ; linePrefixBuilder . append ( "] " ) ; final String linePrefix = linePrefixBuilder . toString ( ) ; out . print ( linePrefix ) ; out . println ( message ) ; if ( t != null ) { t . printStackTrace ( new PrintStream ( out ) { @ Override public void println ( String x ) { synchronized ( this ) { print ( linePrefix ) ; super . println ( x ) ; flush ( ) ; } } } ) ; } }
the throwable if not - null is also prefixed line by line with the prefix