Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Logging to a Console in an application
Logging to a Console in an application [message #536384] Thu, 27 May 2010 22:15 Go to next message
Jon Svede is currently offline Jon SvedeFriend
Messages: 83
Registered: July 2009
Member
I am writing an RCP app using 3.5SR2 and I need to provide a Console to view logging in the app itself. Additionally, my client would like to have a Console window for each editor.

From what I've read this seems quite possible using the existing framework, however, they'd like to add one more thing.

They want to use a logging framework. Currently I am using Pax logging (which is working nicely for logging to the Eclipse console when running the app from eclipse). They want to be able to view the log output in this console (IOConsole? is that right?) My questions are as follows:

1. To satisfy the requirement of being able to view the log in the app via the console or a console-like view, leaving out the logging framework question, is there a simple strategy for writing logging messages to the console?

2. Is it possible to write an Appender for Log4j that can write to a console window? I am relatively new to RCP and this seems possible, but if it were, I'd think someone would have done it and posted a blog or something about it.

Thanks in advance!

Jon
Re: Logging to a Console in an application [message #537037 is a reply to message #536384] Tue, 01 June 2010 06:37 Go to previous messageGo to next message
Patrick Roumanoff is currently offline Patrick RoumanoffFriend
Messages: 19
Registered: July 2009
Junior Member
you can have a look at http://random-eclipse-tips.blogspot.com/2009/03/eclipse-writ ing-to-console-in-rcp.html

or just go ahead, add the org.eclipse.ui.console plugin to your RCP app and add the
org.eclipse.ui.console.ConsoleView to your perspective.

There is a decent API to contribute console page to the console, and you can then either


  • redirect System.out and System.err to your console page
  • write a log4j adapter for your console page.
  • display the content of the log file in the console page.


reference documentation for the extention point is at http://help.eclipse.org/galileo/topic/org.eclipse.platform.d oc.isv/reference/extension-points/org_eclipse_ui_console_con soleFactories.html

[Updated on: Tue, 01 June 2010 06:38]

Report message to a moderator

Re: Logging to a Console in an application [message #537267 is a reply to message #537037] Tue, 01 June 2010 18:08 Go to previous messageGo to next message
Jon Svede is currently offline Jon SvedeFriend
Messages: 83
Registered: July 2009
Member
Thanks, Patrick!

I was able to add the ConsoleView through the extensions and it shows up fine when I launch my app but nothing appears in the view.

My app is using Log4j under the covers (Pax Logging is a wrapper around lo4j, more or less).

I was under the impression (perhaps mistakenly) that by using Log4j and having configured a ConsoleAppender that via RCP/Plug-in magic the view would "automagically" render my logging. I think I may have been overly optimistic.

How does one write Log4j adapter? Are there any docs on this that I could follow?

Thanks!
-- Jon
Re: Logging to a Console in an application [message #537313 is a reply to message #537267] Tue, 01 June 2010 22:35 Go to previous messageGo to next message
Jon Svede is currently offline Jon SvedeFriend
Messages: 83
Registered: July 2009
Member
I found this:

http://jprog.blogspot.com/


which suggested this:

public class MyPerspective implements IPerspectiveFactory {

 public void createInitialLayout(IPageLayout layout) {
  MessageConsole myConsole = new   
     MessageConsole("Console", null); // declare console

   ConsolePlugin.getDefault().getConsoleManager().
      addConsoles(new IConsole[]{myConsole});

  MessageConsoleStream stream = 
    myConsole.newMessageStream();

  PrintStream myS = new PrintStream(stream);
  System.setOut(myS); // link standard output stream to the console
  System.setErr(myS); // link error output stream to the console
 }
}


So far that is working for me.

--Jon
Re: Logging to a Console in an application [message #537438 is a reply to message #537267] Wed, 02 June 2010 13:01 Go to previous message
Patrick Roumanoff is currently offline Patrick RoumanoffFriend
Messages: 19
Registered: July 2009
Junior Member
showing up the console, is not quite enough, you actually need to provide a consoleFactory and a consolePageParticipant. they both are extension points from org.eclipse.ui.console.

there is a good example of that in org.eclipse.team.cvs.ui which contribute a page to the console view.

Once you have your own page, you can write whatever you want in there.

Writing the log4j appender is rather easy since you can just extendWriterAppender to write to your console.

Another option is to just steal System.out/err and redirect that to your console. but you might get more than what you asked for.

p.
Previous Topic:Don't pack Plug-In when deploying
Next Topic:Properties view in German
Goto Forum:
  


Current Time: Sat Apr 20 06:08:38 GMT 2024

Powered by FUDForum. Page generated in 0.03675 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top