Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sniff which Java class (library) is writing to System.out?

Tags:

java

The problem is either tricky or simple (not sure yet):

The project that I'm currently involved with has a bit too many logging libraries. We have log4j, sl4j, logback and who knows what else...

One of these is logging something to System.out and I've run out of ideas on how to find out which one and when...

I'm thinking about something like "putting a breakpoint" on sysout but I don't know if that's even something possible.

Any ideas?

like image 338
Pawel Gorczynski Avatar asked Dec 11 '22 00:12

Pawel Gorczynski


1 Answers

I've used this before on err, to see the actual root cause (instead of the ...and more)

    PrintStream o = new PrintStream(new File("A.txt")) { 
        public void write(byte[] b) throws IOException {
              super.write(b);
              IOException ie = new IOException();
              ie.printStackTrace(); //don't throw this!
        }
    };

and set it like user mentioned above. It's a different method then the one he used, I'm not too sure what the difference is, I just remembered that it worked.

like image 65
Jeff Wang Avatar answered Jan 11 '23 22:01

Jeff Wang