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));