Is it possible to redirect console output to a log file in IntelliJ like Eclipse?

前端 未结 4 1110
Happy的楠姐
Happy的楠姐 2020-12-17 07:59

In Eclipse it\'s possible to redirect console output to a log file using the method outlined here.

Is there a similar feature in IntelliJ IDEA?

4条回答
  •  臣服心动
    2020-12-17 08:01

    Considering the scenario, where you want to capture the log obtained on console via System.out.println("log info") , you could import the following classes :

    import java.io.FileOutputStream;
    import java.io.PrintStream;
    

    and set the output stream to a file like this:

    System.setOut(new PrintStream(new FileOutputStream("log_file.txt")));
    

    This will redirect all the text to the file named log_file.txt . You could also go through this tutorial. Hope this helps. :)

提交回复
热议问题