0

I amtrying to add logging capabilities to my RCP e4 application. I found the following Snippet.

import org.eclipse.e4.core.di.annotations.Creatable;
import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.core.services.log.Logger;
@Creatable
public class LoggerWrapper extends Logger {
@Optional
@Inject
private Logger logger;
@Override
public boolean isErrorEnabled() {
            if (logger != null) {
                    return logger.isErrorEnabled();
            }
            return false;
    }
 @Override
public void error(Throwable t, String message) {
              if (logger != null && isErrorEnabled()) {
                    logger.error(t, withPluginInfo(message));
                  }
}
}     

But I am not sure how to configure/initialize the Logger? Any help will be appreciated. Thanks!

1 Answers1

1

If I read E4Application correctly it will always initialize the application context to contain a Logger which is implemented by org.eclipse.e4.ui.internal.workbench.WorkbenchLogger.

You could override this in the PostContextCreate method of your Life Cycle class (if you have one).

You can also inject StatusReporter which provides simple logging facilities in the Eclipse log (based on Status objects).

greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Thanks for the reply. I am implementing an Eclipse (Kepler) 4 application. As far as I know, an Eclipse 4 Application does not use the workbench. Below is part of my plugin.xml file. Thanks! – user2912941 Nov 21 '13 at 00:48
  • E4 applications do have a workbench but it is not the same as the old workbench. Everything in my answer is for a pure e4 application. – greg-449 Nov 21 '13 at 07:46
  • Thanks!. I tried to search the web to look for examples/usage of the concepts that you stated above. The only useful thing I found was Lars Vogel tutorial at http://www.vogella.com/articles/EclipseLogging/article.html. But it was too brief and does use, I think, the approach you stated above. Any other pointers/examples will be highly appreciated. Once more, thanks for your help. – user2912941 Nov 22 '13 at 01:06
  • Just to follow up on my previous comment. I found these links: "Eclipse4/RCP/Lifecycle" at http://wiki.eclipse.org/Eclipse4/RCP/Lifecycle, "Register for the Eclipse 4 application life cycle - Tutorial" at http://www.vogella.com/articles/Eclipse4LifeCycle/article.html. – user2912941 Nov 22 '13 at 02:32
  • I found this http://www.youtube.com/watch?v=F1t1qxPBfw0&feature=feedu which describes how add logging (log4j) capabilities to an Eclipse 4 Application. – user2912941 Nov 25 '13 at 03:13