如何在OSGi中处理不同的日志记录解决方案(Apache Felix) [英] How handle different logging solutions in OSGi (Apache Felix)

查看:204
本文介绍了如何在OSGi中处理不同的日志记录解决方案(Apache Felix)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OSGi中,日志记录前端和实际输出之间是一个分隔.

In OSGi there is a separation between the logging frontend and the actual output.

因此,通过使用 LogService ,这并不意味着例如将任何内容写入控制台.这就是 LogReaderService 的职责.

So, by using the LogService, this doesnt mean that anything is written to the console for example. This is what a LogReaderService is responsible for.

在当前运行时中,我是addind org.apache.felix.log ,它带来一个LogReaderService-Implementation,该输出应处理输出.但是我仍然看不到控制台上的任何内容...尽管其他捆绑包中有很多其他内容.

In my current runtime, I am addind org.apache.felix.log which brings a LogReaderService-Implementation which should take care of the output. But I still dont see anything on the console...despite a lot of other stuff from other bundles.

在下一步中,我创建了自己的LogListener,应该由LogServiceReader调用.我只是使用了本文中的代码,并调试了激活器以查看是否侦听器已添加.仍然没有输出.

In the next step I created my own LogListener which should be called by a LogServiceReader. I just used the code from this article and debugged the Activator to see if the listener is added. Still no output.

最后,我检查了Felix属性并设置了 felix.log.level = 3 (信息),但同样,没有输出. 我想知道的是,尽管将级别设置为信息",我仍然可以看到很多调试信息吗?

Last I checked the Felix Properties and set felix.log.level=3 (Info) but again, no output. What I was wondering even more that I still could see a lot of DEBUG-Information despite setting the level to Info?

16:47:46.311 [qtp1593165620-27] DEBUG org.eclipse.jetty.http.HttpParser

在我看来,存在不同的日志记录策略,这些策略使用不同的配置属性.例如,在将pax-logging-service(使用经典的日志记录方法)添加到运行时之后,我可以看到输出,但是目前,我想坚持使用felix-logging.

It seems to me that there are different logging strategies in place, which use different configuration properties. For example, after I added the pax-logging-service (which uses a classic logging approach) to my runtime I could see the output, but currently I would like to stick with felix-logging.

有人可以解释一下如何禁用Blueprint-Debug-Level(我猜是造成当前输出的原因),以及通过LogService启用简单的felix-logging吗?即使未在规范中指定.

Can someone please explain how to disable Blueprint-Debug-Level, which I guess is causing the current output, and enable simple felix-logging via LogService? There must be a standard-console-implementation even though its not specified in the spec.

推荐答案

感谢Christian Schneider和Balazs Zsoldos:这两个评论都非常有帮助.

Thanks to Christian Schneider and Balazs Zsoldos: both comments were very helpfull.

要回答这个问题:我需要提供一个 ServiceTrackerCustomizer ,如Balazs示例

To answer the question: I need to provide a ServiceTrackerCustomizer as shown in Balazs example here. Since I already had a ConsoleLogListener it was enough to register the listener with the TrackerCustomizer.

由于我当前的任务是将大型遗留应用程序迁移到我想引入OSGi的地方,因此 Pax-Logging 可能更有意义,因为log4j已经在数百个类中使用了,可能不会更改为LogService.

Since my current task is about migrating a big legacy application where I would like to introduce OSGi it makes probably more sense to go with Pax-Logging since log4j is already used in hundreds of classes which we probably wont change to LogService.

可以通过将属性 org.ops4j.pax.logging.DefaultServiceLog.level 设置为 INFO

The output of Pax-Logging can be adjusted with the property org.ops4j.pax.logging.DefaultServiceLog.level set to INFO

这篇关于如何在OSGi中处理不同的日志记录解决方案(Apache Felix)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆