Using the osgi compendim log service, I can't get my LogReaderService listener
to ever receive a log entry. Note that I'm using the Felix org.apache.felix.log
bundle for the log service.
The super simple bundle code is shown at the bottom of this email.
When debugging in eclipse, a breakpoint in my listener's LogListener.logged()
never gets hit nor does its println() get shown in the eclipse osgi console.
However, I do see all the println()'s in the activator's start() showing up in
the eclipse osgi console; and breakpoints in the start() method get hit as
expected.
If I run the bundle in Felix, again, all the start() method's println()'s get
shown in the Felix console, but the println() in my listener's
LogListener.logged() doesn't get shown in the console. This leads me to believe
that the logged() function is, again, not getting called.
Why is my listener's LogListener.logged() function not getting called?
Thanks in advance.
package com.troppus.bundle.logdriver3.impl;
import org.osgi.framework.*;
import org.osgi.service.log.*;
public class Activator2 implements BundleActivator
{
///////////////////////////////////////////////////////////////////////////////////////////
// Constructors.
public Activator2() {}
///////////////////////////////////////////////////////////////////////////////////////////
// Public attributes.
public void start( BundleContext context ) throws Exception
{
String bundleName = (String)context.getBundle().getHeaders().get(
Constants.BUNDLE_NAME );
System.out.println( bundleName + " starting..." );
m_BundleContext = context;
ServiceReference ref = m_BundleContext.getServiceReference(
LogReaderService.class.getName() );
if (ref != null)
{
LogReaderService reader = (LogReaderService)m_BundleContext.getService(
ref );
reader.addLogListener( new LogWriter() );
m_BundleContext.ungetService( ref );
}
ref = m_BundleContext.getServiceReference( LogService.class.getName() );
if ( ref != null )
{
LogService log = (LogService)m_BundleContext.getService(ref);
System.out.println( "logging a message..." );
log.log( LogService.LOG_WARNING, "a log
message!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" );
System.out.println( "logged a message." );
m_BundleContext.ungetService( ref );
}
System.out.println( bundleName + " started." );
}
public void stop( BundleContext context ) throws Exception
{
// The stop() method should clean up anything done in the start() method.
If you used threads
// in the bundle, wait for all threads to stop before returning from
stop(). Also, if your registered
// services use resources that must be cleaned up, it's prudent to manually
unregister those services
// (i.e. ServiceRegistration.unregister() )before cleaning up the resources
so that noone could
// attempt to use the services without those resources.
String bundleName = (String)m_BundleContext.getBundle().getHeaders().get(
Constants.BUNDLE_NAME );
System.out.println( bundleName + " stopping..." );
m_BundleContext = null;
System.out.println( bundleName + " stopped." );
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private attributes.
private BundleContext m_BundleContext = null;
}
class LogWriter implements LogListener
{
// Invoked by the log service implementation for each log entry
public void logged(LogEntry entry)
{
System.out.println(entry.getMessage());
}
}