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 log
.Add an
@Inject
annotation above theLogService
field.In the
create()
method, add a call to thelog
service.The
Hello
class will look like:import javax.inject.Inject; import org.osgi.service.log.LogService; public class Hello { @Inject private LogService log; @PostConstruct public void create(Composite parent) { label = new Label(parent, SWT.NONE); label.setText("Hello"); log.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 2013-01-24 23:15:51.543 !MESSAGE Hello