Take the 2-minute tour ×  I have some libraries that are calling
System.out.println on me, I'd like to redirect them through
log4j or commons logging. But in particular I'd like to keep the
fully-qualified-classname so I know what component generated the
logs.  Is there a nice, orderly way to accomplish this?  UPDATE:
After accomplishing this I posted the code here:  share|improve
this question  2 Answers 2  up vote 11 down vote accepted  The
only way I can think of would be to write your own PrintStream
implementation which created a stack trace when the println
method was called, in order to work out the class name. It would
be pretty horrible, but it should work... proof of concept
sample code:  import java.io.*;  class TracingPrintStream
extends PrintStream {   public TracingPrintStream(PrintStream
original) {    // You'd want to override other methods too, of
course.   public void println(String line) {     // Element 0 is
getStackTrace     // Element 1 is println     // Element 2 is
the caller     Stack