Question

I'm working with a code base containing over 2500 System.out.println statements. Besides refactoring, is there a way to get them all to send their output to a file? I'm running it using Netbeans 7. Log4j is incorporated into the project, but only a few hundred Logger methods are used within the project.

Was it helpful?

Solution

The fact your code base uses log4j is rather irrelevant, since the System.out.println calls you want to redirect bypass the whole logging framework.

My first suggestion would be to replace the System.out.println calls by a log statement. A find-and-replace should almost allow you to do this.

Otherwise, you can just set another PrintStream as System.out using System.setOut. Example of this can be found here and here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top