Eclipse Console Window

Here’s a quick code snippet for using the Console view that is included with the standard Eclipse views when using RCP.  In the example, I am using the output from Log4J and streaming it to the Console.

The Console import declarations are:


import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;

The code that you will need to create the Console and direct the Logging output to the console is:


// Connect the Logging output to the console view.
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager consoleManager = plugin.getConsoleManager();
MessageConsole console = new MessageConsole("Console", null);
consoleManager.addConsoles(new IConsole[] { console });

logger = Logger.getLogger("default");
logger.addAppender(new WriterAppender(new SimpleLayout(), console.newMessageStream()));

And that is basically it. All output to the logger is now streaming to the Console window in the application.

This entry was posted in Eclipse, Software. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *