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.
Open the
Hello
class and add aprivate
fieldLogService logService
.Add an
@Inject
annotation to theLogService
field.In the
create
method, add a call to the log service.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"); } ... }
Run the application, and a log message will be printed out to the console of the host Eclipse:
!ENTRY org.eclipse.e4.ui.workbench 4 0 2016-06-02 13:36:42.381 !MESSAGE Hello