My current application uses Logback for logging. I have used Apache Felix to deploy an OSGi framework that allows bundles to be dynamically registered at runtime. The Felix setup is as follows:
...
//System.out.println("Building OSGi Framework");
FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next();
Map<String, String> config = new HashMap<>();
// specify the class loader
config.put(Constants.FRAMEWORK_BUNDLE_PARENT, Constants.FRAMEWORK_BUNDLE_PARENT_FRAMEWORK);
// specify the osgi cache directory
config.put(Constants.FRAMEWORK_STORAGE, appConfig.getOsgiCacheDir());
// make sure the cache is cleaned
config.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
// expose api
config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "list.of.packages.to.export");
// more properties available at: http://felix.apache.org/documentation/subprojects/apache-felix-service-component-runtime.html
config.put("ds.showtrace", "false");
config.put("ds.showerrors", "true");
config.put("felix.fileinstall.dir", appConfig.getActiveOsgiExtDir());
config.put("felix.fileinstall.tmpdir", appConfig.getTempOsgiExtDir());
config.put("felix.fileinstall.bundles.startTransient","true");
config.put("felix.fileinstall.poll","5000");
config.put("felix.fileinstall.bundles.new.start", "true");
LOG.debug("OSGi config: " + config.toString());
framework = frameworkFactory.newFramework(config);
try {
framework.init();
FrameworkEvent event;
do {
framework.start();
...
The only problem is that there seems to be no logging with Felix. When a bundle fails to load for some reason I can't see why! I know that I can use the following in the bundle to obtain the parent logger:
ServiceReference ref = bundleContext.getServiceReference(LogService.class.getName());
if (ref != null) {
LogService log = (LogService) bundleContext.getService(ref);
...
}
However, I don't understand how I can get felix to use logback as the logger in the first place.