Time for action – adding logging

The OSGi platform defines a LogService which allows messages to be logged to a central collector. In the E4 platform, an instance of LogService is available as part of the platform, routing error messages through to the console.

  1. Open the Hello class and add a private field LogService logService.
  2. Add an @Inject annotation to the LogService field.
  3. In the create method, add a call to the log service.
  4. The Hello class will look like:
    import javax.inject.Inject; import org.osgi.service.log.LogService; public class Hello { @Inject private LogService logService; @PostConstruct public void create(Composite parent) { label = new Label(parent, SWT.NONE); label.setText("Hello"); logService.log(LogService.LOG_ERROR, "Hello"); } ...

Get Eclipse Plug-in Development Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.