Does pax logging support standard osgi log service api

153 views Asked by At

I configured pax logging on my osgi runtime and test standard osgi log service but the logging was not recorded. Anyway all other logging API's seems to be working as [2] expected. Do I miss anything ?

LogService logService;

public void start(BundleContext bundleContext) throws Exception {

    ServiceReference ref = bundleContext.getServiceReference(LogService.class.getName());
    if (ref != null)
    {
        logService = (LogService) bundleContext.getService(ref);
        logService.log(LogService.LOG_INFO, " -----------  Testing OSGI logging on bundle start  -------------------- ");
}

[1] https://ops4j1.jira.com/wiki/display/paxlogging/Installation

[2] https://ops4j1.jira.com/wiki/display/paxlogging/Pax+Logging

Thanks

1

There are 1 answers

0
David M. On

It is a classic mistake with OSGi: you expect the LogService to be available at start up time. If it is delayed, you end up having a null reference and not logging anything.

Try using a standard method of injecting services when they get published, like the Declarative Services component model.

A good tutorial can be found on the IBM Infocenter.