skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Thursday, October 4, 2012

Redirecting System.out and System.err over Log4j

Posted by Admin at 11:26 AM – 0 comments
 

The Log4j is the new technique for logging all the information in the application and it is a replacement of System.out. If the application already has System.out in all programs and we want to change it to Log4j, then we have to replace all the System.out statements in the application which is tedious process. Instead, there is a technique for redirecting all the System.out and System.err messages in the application.


Logger err = Logger.getLogger("SystemErr");Level warn = Level.WARN;System.setErr(new PrintStream(new LoggingOutputStream(err, warn), true));Logger out = Logger.getLogger("SystemOut");Level info = Level.INFO;System.setOut(new PrintStream(new LoggingOutputStream(out, info), true));

Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger