This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets forum!
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: 2833
    
  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: 8836
    
    7

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: http://aspose.com/file-tools
 
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