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

前端 未结 4 1105
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. :)

    0 讨论(0)
  • 2020-12-17 08:23

    UPDATE: this feature is available in IDEA 11.

    Not possible in IDEA at the moment, I've submitted a new feature request. Feel free to vote.

    A workaround could be implemented using wrapper class with main() method which will redirect stdout and stderr to files and then run the main class of your application.

    0 讨论(0)
  • 2020-12-17 08:25

    In more recent versions of IntelliJ this is possible. Go to the "Logs" tab of a run configuration. There is a "Save console output to file option".

    I'm on IntelliJ 13.1.3 but I think this feature has been around for a while.

    0 讨论(0)
  • 2020-12-17 08:25

    Possible redirect console output to a log file. Run -> Edit Configurations . To see Run/Debug Configurations window Then go tab : Logs, check in "Save console output to file:" and fill to path file (example D:\logtoFile.txt) Reference here : https://www.jetbrains.com/help/idea/2017.1/setting-log-options.html

    0 讨论(0)
提交回复
热议问题