Add the error log view to your Eclipse RCP application

The Eclipse platform provide error message in case something goes wrong.

During development I use the launch parameter -consoleLog to see if any error has occured. I assume most plugin developer use -consoleLog that is why I opened Bug for making -consoleLog a default in a new launch configuration.

Obviously you don’t want your users to check the console for errors. To make errors visible to the user you can add the exiting error log to your RCP application.

Create a new Eclipse RCP project “de.vogella.rcp.intro.errorview” for this purpose. Use the “Hello RCP” as a template.

Select the plugin.xml and add the dependency to org.eclipse.ui.views.log.

Ddd the standard Eclipse command “org.eclipse.ui.views.showView” to your menu under the Entry “Admin”. See Eclipse Commands how to do this.

This will result in the following plugin.xml


<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>

   <extension
         id="application"
         point="org.eclipse.core.runtime.applications">
      <application>
         <run
               class="de.vogella.rcp.intro.errorview.Application">
         </run>
      </application>
   </extension>
   <extension
         point="org.eclipse.ui.perspectives">
      <perspective
            name="RCP Perspective"
            class="de.vogella.rcp.intro.errorview.Perspective"
            id="de.vogella.rcp.intro.errorview.perspective">
      </perspective>
   </extension>
   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="menu:org.eclipse.ui.main.menu">
         <menu
               label="Admin">
            <command
                  commandId="org.eclipse.ui.views.showView"
                  label="Show Error View"
                  style="push">
               <parameter
                     name="org.eclipse.ui.views.showView.viewId"
                     value="org.eclipse.pde.runtime.LogView">
               </parameter>
            </command>
         </menu>
      </menuContribution>
   </extension>

</plugin>

Run your new application. You should have a menu entry “Admin” with an entry “Show Error View”. If you select it the error view should open.

errorLogView10

About Lars Vogel

Lars Vogel is the founder and CEO of the vogella GmbH and works as Eclipse and Android consultant, trainer and book author. He is a regular speaker at international conferences, He is the primary author of vogella.com. With more than one million visitors per month this website is one of the central sources for Java, Eclipse and Android programming information.
This entry was posted in Eclipse and tagged , . Bookmark the permalink.

25 Responses to Add the error log view to your Eclipse RCP application

  1. Jacek says:

    all true. Is there anything that log view is missing from RCP consumers point of view?

  2. Lars Vogel says:

    @Jacek Not that I’m aware of

  3. Martin says:

    Any examples on how to use/fill the error log?

  4. Lars Vogel says:

    @Martin: if you have for example an exception it will be shown in the error view

  5. Martin says:

    I would like to fill the log view with my own log messages, I have found something like:

    Status status = new Status(IStatus.INFO,”Test”,”Test string!”);
    WorkbenchPlugin.log(status);

    but I get some warnings:
    Multiple markers at this line
    – Discouraged access: The method log(IStatus) from the type WorkbenchPlugin is not accessible due to restriction on required library C:\Programme
    \eclipse\plugins\org.eclipse.ui.workbench_3.4.2.M20090127-1700.jar
    – Discouraged access: The type WorkbenchPlugin is not accessible due to restriction on required library C:\Programme\eclipse\plugins
    \org.eclipse.ui.workbench_3.4.2.M20090127-1700.jar

    so how should i access the log view?

  6. Lars Vogel says:

    @Martin: I had a similar problem. I posted a question to this topic but the only answer I got was that I should turn of the corresponding check:

    http://dev.eclipse.org/newslists/news.eclipse.platform.pde/msg02084.html

  7. I used the logger with:

    Activator.getDefault().getLog().log(status);

    and all messages are shown in the logView.

    Is there a way to avoid, the View jumps to foreground?

  8. Lars Vogel says:

    @Uwe Not sure what you mean; if the view is not open is also will not be displayed if messages get added to the view.

  9. Thats right. My intention was to have another view in the foreground but log all messages in the background. A solution could be to use the log view as fast view. Is this possible with an RCP application?

  10. Lars Vogel says:

    @Uwe Yes this is possible. For the general concept please see here: http://www.vogella.de/articles/RichClientPlatform/article.html If the view should be a fast view, just use “relationship” “fast” in the perspectiveExtension

  11. Lars Vogel says:

    @Uwe: You also have to enable the fast view pane in ApplicationWorkbenchWindowAdvisor via configurer.setShowFastViewBars(true); in method preWindowOpen()

  12. Pingback: Using Fast Views in Eclipse RCP » Eclipse Papercuts

  13. Fernando says:

    Hello,
    I was wondering if there’s a way to modify the error log view so that it can, for example, be in other language. I speak spanish and the application I’m developing is going to be in spanish too, since I need a view pretty much similar to the Error Log View (with a small changes, besides the language) I thought that maybe there could be a way to obtain the source code of the view and change according to my need. Could you tell me if that’s possible? Thank you

  14. Lars Vogel says:

    @Fernando yes, you can get the source code and modify it. See http://www.vogella.de/articles/EclipseCodeAccess/article.html for a guide to access the source code of Eclipse. To find the code of the view you can use the Plugin Spy.

  15. Fernando says:

    Thanks a lot. Now, since I want to modify it, of course I shouldn’t import the binaries, but the source folders instead. Is there any legal prohibition for modifying the source code of standard eclipse views and use it as part of my Eclipse RCP application?
    Another question (and I know it must sound a little stupid). What I should do next is modify this source code obtained and, since it is already a plug in, add it to my project and used it right. Should I change the name of it? (again por legal reasons?).
    Thanks again.

  16. Lars Vogel says:

    @Fernando I’m not an legal expert but as far as I now the EPL allow you to do what you want.

  17. Fernando says:

    Ok, thanks!

  18. Michael Schmidt says:

    This does not seem to work with eclipse 3.6, just to let you know.

  19. Lars Vogel says:

    @Michael: What is the problem with Eclipse 3.6?

  20. Shyam says:

    I am regular user of your inputs. Thanks :)

    I was wondering, instead of error view [which will scare the hell out of my customers], I would like to catch all the exceptions on my client.log file. Every now and then I get an instance where the client seems to poof out and when I go to their location and look for .metadata/.log I see some exception. How can I avoid such cases or at least catch these “out of the blue” exceptions on my log file. I email this to myself at the end of day.

    Thanks.

    Shyam.

  21. Lars Vogel says:

    @Shyam: Sorry but I have not done such a thing.

  22. Nick says:

    Any idea how to avoid seeing all Log views (e.g. Bookmarks) in ContributionItemFactory.VIEWS_SHORTLIST, e.g. Window | Show View…?

  23. Lars Vogel says:

    @Nick you can just use your own command to show the view: http://www.vogella.de/articles/EclipseCommands/article.html

  24. Mahesh says:

    When i added a dependency to org.eclipse.ui.views.log and from code i wanted to show the Error view

    addView(
    “org.eclipse.pde.runtime.LogView”
    , IPageLayout.BOTTOM
    , 0.75f
    , “SomeViewID”
    );

    But as long as the dependency is there i get error java.lang.RuntimeException: No application id has been found.

    The moment i remove this dependency my application runs fine. Any suggestions ?

  25. Lars Vogel says:

    @Mahesh I suggest to add this plugin to your launch configuration.

Comments are closed.