My application has many System.out.println() statements.
I want to catch messages from println and send them to the standard logger (Log4j, JUL etc).
How to do that ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The System class has a
setOutandsetErrthat can be used to change the output stream to, for example, a newPrintStreamwith a backingFileor, in this case, probably another stream which uses your logging subsystem of choice.Keep in mind you may well get yourself into trouble if you ever configure your logging library to output to standard output or error (of the infinite recursion type, possibly).
If that’s the case, you may want to just go and replace your
System.out.print-type statements with real logging calls.