简体   繁体   中英

Activating an OSGI LogListener before other services?

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 (ie desktop not server, so no PAX or Karaf; Maven; and I use NetBeans, so no Eclipse).

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM