aspose file tools*
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
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Redirecting sysout to log file" Watch "Redirecting sysout to log file" New topic
Author

Redirecting sysout to log file

Midhun Agnihotram
Greenhorn

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.

Thanks,
Midhun
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2861
    
  11

You can redirect sysout and syserr using statments like: System.setOut(myPrintStream). There's a good discussion of it here: http://blogs.sun.com/nickstephen/entry/java_redirecting_system_out_and.

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
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

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).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Redirecting sysout to log file