0

In my company in our project we have lot of system.out.prinltn and we are finding very difficult to see all logs on console. is it possible to capture the system.out.println to a file? Thanks

  • have you tried anything??? – sanoj lawrence Feb 01 '15 at 05:24
  • The easiest way is on OS level, just redirect stdout to a file when you start the process. – Henry Feb 01 '15 at 05:27
  • *"In my company in our project we have lot of system.out.prinltn ..."* - Then you have a serious problem with Code Quality in your company. It is likely to burn you ... or your clients / customers ... in the long term. – Stephen C Feb 01 '15 at 05:33

2 Answers2

1

Yes, it's possible to redirect stdout on DOS or any *nix type Operating System.

java -jar somefile.jar > my_file.txt

If you're using a *nix system you can also use the tee command (which will output to the stdout and to a file) like

java -jar somefile.jar | tee my_file.txt

Both also support appending to the file

java -jar somefile.jar >> my_file.txt

or

java -jar somefile.jar | tee -a my_file.txt
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0

There are plenty of ways to achieve this, the easiest one is while running through command prompt

java class_name >file_name.txt

It would be great if you can provide more details on this.