Reputation: 6353
When any applications runs, we can see logs in eclipse console for example launching browser etc. I just want to read that. Please provide any sample code for reading these console logs in Java.
Upvotes: 2
Views: 9132
Reputation: 4216
If I am not wrong, you are trying to read Eclipse Console logs. If so, then I can assure you that you can do that. Not, only that , you can also write something in Eclipse Console.
First search if the console exists at all-
private static MessageConsole findConsole(String name) {
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager conMan = plugin.getConsoleManager();
IConsole[] existing = conMan.getConsoles();
for (int i = 0; i < existing.length; i++)
if (name.equals(existing[i].getName()))
return (MessageConsole) existing[i];
}
if it exists, then run the following code
MessageConsole myConsole = findConsole("CVS"); // calls the above method
if(myConsole!=null){
IDocument doc = myConsole.getDocument();
inputData = doc.get();
if (inputData != null)
inputData = inputData.trim();
if (inputData != null && !inputData.equals("")) {
//Sysout here the inputData or store in some file
}
}
For more, try this link . It is Helpful - http://javacodingtutorial.blogspot.com/2013/10/how-to-create-plug-in-that-reads-any.html
Upvotes: 1
Reputation: 189
I honestly do not know if this is the thing that you're asking for, but would logging the console to file and reading it be okay?
Logging to file can be done from :
Run/Debug settings -> Common -> Standard Input and Output (it can even write to console and file at the same time).
Then it's just basic file handling in Java. Is this what you're looking for?
Upvotes: 1
Reputation: 21223
You can try IConsoleLineTracker
. Here is an example implementation.
Upvotes: 2