Activating an OSGI LogListener before other services?

回眸只為那壹抹淺笑 提交于 2020-01-04 11:40:05

问题


I am writing a OSGI-based desktop application, using Apache Felix, Declarative Services and Maven. It's going to use JavaFX, so I'm using Drombler FX too.

In the bundles I develop, I'd like to use an appropriate logging mechanism, and I'm currently trying to make Apache Felix Log work. I have no problem getting a LogService but this is not sufficient to make output appear on the console.

The word on the net is that Everit's osgi-loglistener-slf4j will do the job and – sure enough – after osgi-loglistener-slf4j has been activated log output appears on the console.

However, osgi-loglistener-slf4j is not activated until after all my own bundles, so none of the log information that I am interested in is output. I've tried creating a @Reference to a LogLevel in my first bundle to try and force activation of osgi-loglistener-slf4j, but without success.

How do I get osgi-loglistener-slf4j activated before everything else? I have read about start levels, but I haven't been able to find any information about how to apply them in my context (i.e. desktop not server, so no PAX or Karaf; Maven; and I use NetBeans, so no Eclipse).


回答1:


Drombler FX uses SLF4J: http://www.drombler.org/drombler-fx/0.7/docs/tutorial/logging.html#logging

Just use the following and it should work:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;  

...

private static final Logger LOG = LoggerFactory.getLogger(MyClass.class);

In the POM add the following dependency:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>


来源:https://stackoverflow.com/questions/34572970/activating-an-osgi-loglistener-before-other-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!