OSGI 下的 Log4j (Eclipse RCP)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5150415/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:53:21  来源:igfitidea点击:

Log4j under OSGI (Eclipse RCP)

eclipselog4josgircp

提问by marcolopes

After many tests i concluded that the Log4j is not working under OSGI.

经过多次测试,我得出结论,Log4j 不能在 OSGI 下工作。

I do not use Log4j directly, but i need third party plugins to log with it.

我不直接使用 Log4j,但我需要第三方插件来使用它进行登录。

I made a plain JAVA project and everything works great, but under PLUGIN development nothing works.

我做了一个普通的 JAVA 项目,一切正常,但在插件开发下没有任何效果。

I have log4j jar in my Classpath and even tried a Spring repository OSGI compliant Log4j and included it under Dependencies. Nothing works.

我的类路径中有 log4j jar,甚至尝试了一个 Spring 存储库 OSGI 兼容的 Log4j 并将其包含在依赖项下。没有任何作用。

I've tried this some approach with no success: http://swik.net/Eclipse/Planet+Eclipse/Raja+Kannappan:+Eclipse+RCP+-+Converting+Dependencies+to+OSGi+Bundles/drqpf

我试过这种方法没有成功:http: //swik.net/Eclipse/Planet+Eclipse/Raja+Kannappan:+ Eclipse+RCP+-+Converting+Dependencies+to+OSGi+Bundles/ drqpf

and could not fully understand this one: http://www.eclipsezone.com/eclipse/forums/t99588.html

并不能完全理解这一点:http: //www.eclipsezone.com/eclipse/forums/t99588.html

Can anyone point me on the right direction?

任何人都可以指出我正确的方向吗?

Thanks.

谢谢。

回答by Eugene Ryzhikov

You simply have to create log4j fragment bundle with the log4j.properties file inside.

您只需要创建带有 log4j.properties 文件的 log4j 片段包

UPDATE: Some things to look for:

更新:一些需要寻找的东西:

  • Header name should be: Fragment-Host: log4j.
  • log4j.propertiesshould be in the srcfolder.
  • All the bundles which use log4j should have org.apache.log4jin their Import-Packageattribute
  • 标题名称应为:Fragment-Host: log4j
  • log4j.properties应该在 src文件夹中。
  • 所有使用 log4j 的包都应该org.apache.log4j在它们的Import-Package属性中

回答by RaduK

For logging in OSGi, you should take a look at OSGi Log Service. Here is article that explains quite well a good approach: http://blog.kornr.net/index.php/2008/12/18/osgi-logging-putting-it-all-together

要登录 OSGi,您应该查看 OSGi 日志服务。这里的文章很好地解释了一个很好的方法:http: //blog.kornr.net/index.php/2008/12/18/osgi-logging-putting-it-all-together

You can also take a look at Pax-Logging: http://wiki.ops4j.org/display/paxlogging/Pax+Logging

您还可以查看 Pax-Logging:http: //wiki.ops4j.org/display/paxlogging/Pax+Logging