When you are running/debugging an application in Eclipse, output or any logging information of your application is sent to the console. While you can check Eclipse console box for diagnosis and debugging, the Eclipse console can only preserves the last bit of program output/logs, not the entire history. So if your program generates a huge size of output/logs, you may want to save console output to a separate file for offline inspection. There are two ways of doing it.
The first method is to tell Eclipse to save console output to a file. For that, go to Run -> Debug Configurations on Eclipse menu. Then under "Standard Input and Output" section, click on checkbox next to "File:", and choose the name of output file to use. If you check "Append" underneath, console output will be appended to the output file. Otherwise, console output will be overwritten to the file.
The other approach is to explicitly redirect console output to a file within your program itself. If your program is written in Java, you can add the following code at the beginning of your program.
System.setOut(new PrintStream(new FileOutputStream("output.txt"))); System.out.println("This is test output");
Then, all console output generated by System.out.* will be redirected to the output file.
Subscribe to Xmodulo
Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!
Latest posts by Dan Nanni (see all)
- How to install Suricata intrusion detection system on Linux - September 3, 2015
- How to switch from NetworkManager to systemd-networkd on Linux - August 31, 2015
- How to set up a system status page of your infrastructure - August 25, 2015