Meaningless Drivel is fun!*
The moose likes I/O and Streams and the fly likes Redirecting sysout to log file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Redirecting sysout to log file" Watch "Redirecting sysout to log file" New topic

Redirecting sysout to log file

Midhun Agnihotram

Joined: Feb 20, 2010
Posts: 11
Hi All,

We have a Spring and Hibernate based J2EE application. Even though there is a logger mechanism created using log4j, many System.out.println statements are used.

As per my knowledge, Sysouts effect the performance of the application. Is there a way to redirect all Sysouts to the logger file so that it boost the performance a bit ? I donot want to change the Sysouts in all files as it is huge code base.

Greg Charles

Joined: Oct 01, 2001
Posts: 2840

You can redirect sysout and syserr using statments like: System.setOut(myPrintStream). There's a good discussion of it here:

However, what would really be better is updating all those println()s to log() statements. Log4j will give you a lot more control over where the logs go and what they will contain.
Joe Ess

Joined: Oct 29, 2001
Posts: 8836

Greg Charles wrote:Log4j will give you a lot more control over where the logs go and what they will contain.

Java has a built in logging API, in case you are wary of third parties (though I use Log4J myself).
I agree. Here's the link:
subject: Redirecting sysout to log file
Similar Threads
Logger for each Thread
jcl and Log4J in WAS V7
Loading a class
Logger for each Thread
Sysouts in AOP logger