1

我在我的 osgi 运行时配置了 pax 日志记录并测试了标准 osgi 日志服务,但没有记录日志记录。无论如何,所有其他日志记录 API 似乎都按 [2] 的预期工作。我想念什么吗?

LogService logService;

public void start(BundleContext bundleContext) throws Exception {

    ServiceReference ref = bundleContext.getServiceReference(LogService.class.getName());
    if (ref != null)
    {
        logService = (LogService) bundleContext.getService(ref);
        logService.log(LogService.LOG_INFO, " -----------  Testing OSGI logging on bundle start  -------------------- ");
}

[1] https://ops4j1.jira.com/wiki/display/paxlogging/Installation

[2] https://ops4j1.jira.com/wiki/display/paxlogging/Pax+Logging

谢谢

4

1 回答 1

1

这是 OSGi 的一个典型错误:您希望 LogService 在启动时可用。如果它被延迟,你最终会得到一个null参考并且没有记录任何东西。

尝试在服务发布时使用标准方法注入服务,例如声明式服务组件模型

可以在 IBM Infocenter 上找到一个很好的教程。

于 2014-02-14T11:15:21.877 回答