|
Re: Problem finding LogReaderService to register LogListener [message #95772 is a reply to message #95756] |
Thu, 23 August 2007 10:09 |
Pedro Silva Messages: 25 Registered: July 2009 |
Junior Member |
|
|
I've found the problem ... basic error ... I forgot to add the bundle
org.eclipse.equinox.log to the bundles that where started when the
application was launched.
Pedro Silva wrote:
> Hi,
> I'm giving the first steps in OSGi and Equinox and after making som
> simple HelloWorld exercises i'm trying to make something more advanced.
> What i'm trying to do is to register a new LogListener through
> LogReaderService that will collect my other bundles log messages.
>
> My problem right now is that I can't seem to find the LogReaderService.
> I've followed some examples that I've found on the net in order to
> register the LogListener. Just to start I'm trying to find the
> LogReaderService so that I can use the addLogListener method, the
> problem is that LogReaderService always comes back null ... If I type
> log in OSGI console I get: "The LogReaderService is not registered.",
> what am I missing???
>
> Thanks in advance,
> Pedro
>
> Code to find LogReaderService:
>
> import org.osgi.framework.BundleActivator;
> import org.osgi.framework.BundleContext;
> import org.osgi.service.log.LogReaderService;
> import org.osgi.util.tracker.ServiceTracker;
>
> public class Activator implements BundleActivator {
>
> private LogReaderService logReaderService;
>
> public void start(BundleContext context) throws Exception {
> ServiceTracker st = new ServiceTracker(context,
> LogReaderService.class.getName(), null);
> st.open();
> logReaderService = (LogReaderService) st.getService();
> if (logReaderService != null) {
> System.out.println("LogReaderService not found");
> } else {
> System.out.println("LogReaderService found");
> }
> st.close();
> }
>
> public void stop(BundleContext context) throws Exception {
> }
>
> }
> Hi,
> I'm giving the first steps in OSGi and Equinox and after making som
> simple HelloWorld exercises i'm trying to make something more advanced.
> What i'm trying to do is to register a new LogListener through
> LogReaderService that will collect my other bundles log messages.
>
> My problem right now is that I can't seem to find the LogReaderService.
> I've followed some examples that I've found on the net in order to
> register the LogListener. Just to start I'm trying to find the
> LogReaderService so that I can use the addLogListener method, the
> problem is that LogReaderService always comes back null ... If I type
> log in OSGI console I get: "The LogReaderService is not registered.",
> what am I missing???
>
> Thanks in advance,
> Pedro
>
> Code to find LogReaderService:
>
> import org.osgi.framework.BundleActivator;
> import org.osgi.framework.BundleContext;
> import org.osgi.service.log.LogReaderService;
> import org.osgi.util.tracker.ServiceTracker;
>
> public class Activator implements BundleActivator {
>
> private LogReaderService logReaderService;
>
> public void start(BundleContext context) throws Exception {
> ServiceTracker st = new ServiceTracker(context,
> LogReaderService.class.getName(), null);
> st.open();
> logReaderService = (LogReaderService) st.getService();
> if (logReaderService != null) {
> System.out.println("LogReaderService not found");
> } else {
> System.out.println("LogReaderService found");
> }
> st.close();
> }
>
> public void stop(BundleContext context) throws Exception {
> }
>
> }
|
|
|
Re: Problem finding LogReaderService to register LogListener [message #96188 is a reply to message #95756] |
Wed, 29 August 2007 11:56 |
Neil Hatherly Messages: 1 Registered: July 2009 |
Junior Member |
|
|
Hi, I'd like to hijack this thread since I have a very similar problem.
I'm trying to use the log service in my application and I'm not having much success.
I have a class which extends ServiceTracker and should track the org.osgi.service.log.LogReaderService service. This is done in the contructor of my LogReaderServiceTracker class:
...
<i>super(bundlecontext, LogReaderService.class.getName(), null);</i>
...
The class also holds an instance of my FileLogger class, which implements the LogListener interface to receive log entries.
Then my central bundle instanciates the LogReaderServiceTracker in the start-method of its activator:
...
<i>logReaderServiceTracker = new LogReaderServiceTracker(bundlecontext);
logReaderServiceTracker.open();</i>
...
Next, I try and retrieve the LogReaderService to add the FileLogger as a listener:
...
<i>LogReaderService logReader = (LogReaderService) logReaderServiceTracker.getService();</i>
...
The problem: logReader is always null. I assume that no LogReaderService was started?
I'm puzzled by this, since I have included all relevant bundles (osgi.core, osgi.compendium, org.eclipse.osgi.services, org.eclipse.equinox.log) in my launch configuration. I haven't even yet got so far as to start the application from console.
Can anyone provide a pointer here?
Many thanks in advance,
Neil
|
|
|
Powered by
FUDForum. Page generated in 0.03273 seconds