Duplicate all the terminal output to file

已回答

I want to write a Jetbrains IntelliJ plugin which aims to duplicate all the terminal output to some files with timestamp. Directly change the direction of System.out when coding is not I want, and the recording is executed passively by the plugin, so it's just a duplicate of terminal information. Thus, how can I implement it?

For example, File_7891242885.log records "Hello World!" and other terminal output when I executed the class at timestamp 7891242885.

评论操作 固定链接

Hi,

Could you please clarify your use case? Do you want to additionally write everything that is printed to the Terminal tool window to a log file, is it correct? Or do you want to log some specific information? You mention "executing a class" - what does it mean? What tool window are you referring to? Are you sure you mean Terminal or maybe Build or Run tool window? Screenshots would be helpful as well.

0
评论操作 固定链接

Karol Lewandowski Thank you for your reminding! Yes I want to write everything that is printed to the Terminal tool window to a log file, my objective is just to collect these data for further data analysis of the procedure of programming.

About "executing a class", it's just a example when someone write and execute a simple introductory Java "Hello World" program. I think there is some output printed in the terminal, is it right? I want to record such output in a new text file.

Is there any interface of IntelliJ Plugin API could be used to connect terminal that I could get such output?

The terminal is like this:

0
评论操作 固定链接

Hi, this is not the Terminal tool window but the Run tool window. They are different things.

There is no simple API that would allow doing what you need, but the Run (and many other) console contents are rendered by using Editor API, which operates on a Document object, and you can listen to document changes.

To register a document listener, use:

EditorFactory.getInstance()
.getEventMulticaster()
.addDocumentListener(new MyDocumentListener(), ApplicationManager.getApplication());

e.g., in postStartupActivity EP. In the listener, you can listen for the content added to consoles. Note that this will listen to all documents, so also edited code. Ensure you handle only the documents related to the consoles you want to track.

1
评论操作 固定链接

Thank you very much! I did some simple filtering of the text getting from the listener and it works well in my scenario.

0

请先登录再写评论。