简体   繁体   English

在其他服务之前激活OSGI LogListener?

[英]Activating an OSGI LogListener before other services?

I am writing a OSGI-based desktop application, using Apache Felix, Declarative Services and Maven. 我正在使用Apache Felix,Declarative Services和Maven编写基于OSGI的桌面应用程序。 It's going to use JavaFX, so I'm using Drombler FX too. 它将使用JavaFX,所以我也使用了Drombler FX

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. 在我开发的捆绑软件中,我想使用一种适当的日志记录机制,并且我目前正在尝试使Apache Felix Log工作。 I have no problem getting a LogService but this is not sufficient to make output appear on the console. 我获取LogService没问题,但这不足以使输出出现在控制台上。

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. 网上的消息是,Everit的osgi-loglistener-slf4j将完成此工作,并且-确实-在激活osgi-loglistener-slf4j之后,控制台上会出现日志输出。

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. 但是,直到我拥有了所有捆绑包之后osgi-loglistener-slf4j激活,因此,我感兴趣的日志信息都不会输出。 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. 我尝试在我的第一个捆绑软件中创建对LogLevel@Reference ,以尝试强制激活osgi-loglistener-slf4j ,但是没有成功。

How do I get osgi-loglistener-slf4j activated before everything else? 我如何osgi-loglistener-slf4j激活osgi-loglistener-slf4j 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). 我已经阅读了有关开始级别的信息,但是我找不到有关如何在我的上下文中应用它们的任何信息(即台式机不是服务器,因此没有PAX或Karaf; Maven;并且我使用NetBeans,因此没有Eclipse)。

Drombler FX uses SLF4J: http://www.drombler.org/drombler-fx/0.7/docs/tutorial/logging.html#logging Drombler FX使用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: 在POM中添加以下依赖项:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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