开发者

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

In Eclipse it's possible to redirect console output to a lo开发者_如何学Cg file using the method outlined here.

Is there a similar feature in IntelliJ IDEA?


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.


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.


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. :)


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


IntelliJ IDEA 2021.3.3 (Ultimate Edition), follow the steps:

  • Run/Debug Configurations dialog: where you boot up your application
  • Modify options: a scrolldown bar hard to locate
  • Logs: scroll down, and there is a section for logs
  • Save console output to file
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜