登录Eclipse / OSGi插件 [英] Logging in Eclipse/OSGi plugins

查看:116
本文介绍了登录Eclipse / OSGi插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始开发一个Eclipse插件(从技术上说是一个OSGi插件),而且我遇到的第一个问题之一就是我通常不会像通常那样控制公共记录输出。 p>

我将commons-logging软件包包含在插件依赖项中,实际上当我记录某些东西(INFO或更高的严重性)时,它被记录到控制台。但是,我似乎无法登录任何较低级别(如DEBUG或TRACE)。



我已经指定了一个log4j.properties文件,它在classpath(对于运行时,就像commons-logging软件包一样),但该属性文件中的任何设置都不会对记录器的行为产生任何影响。



这里是log4j.properties文件:

 #Log4j按重要程度降低的顺序为:
#致命,错误,WARN,INFO,DEBUG,TRACE


#根记录器选项
log4j.rootLogger = ERROR,stdout
#,LOGFILE

#直接日志消息到stdout
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern =%d {ABSOLUTE}%5p%r(%l)%t%n - %m%n

我需要做什么才能实际控制输出记录器?



以下是一些示例输出消息,希望格式可能与java.util.logging的默认值一致,或向某人提供其他提示:

  2008年10月21日11:01:23 PM com.stottlerhenke.sentinel.client.Activator start 
SEVERE: fatal_message
2008年10月21日11:01:23下午com.stottlerhenke.sentinel.client.Activator启动
警告:warn_message
2008年10月21日下午11:01:23 com.stottlerhenke。 sentinel.client.Activator start
INFO:info_message

更新:



我现在尝试了以下各种组合:





我可以只有获取DEBUG或更低级别的消息出现,如果我从一个提示手动运行OSGi(这是不切实际的为我正在开发的)。此外,我不能通过各种属性文件影响任何其他类型的日志配置。在这方面,我尝试的一切似乎都被eclipse设置所覆盖。



我也尝试过将各种配置文件放在上面的库中,包括作为插件 - 附加到各自图书馆的片段,如建议的此处,并且仍然是结果发生。



我已经实现了一个自定义LogListener,并跟踪了System.out的日志消息的整个路径(以及我知道的方式)。 println和调试消息 直到它们被我使用的任何底层日志记录API输出,然后消失。

解决方案

3天后...



我发现问题!有两件事我需要做,首先,一个MANIFEST.MF文件有一个问题:



我在MANIFEST.MF中有以下一个包:

  Bundle-ClassPath:lib / jena.jar,
。,
org.apache.log4j -1.2.12.jar,
lib / google-collect-snapshot.jar
导入包:com.acme.client.translation,
com.acme.translation.interfaces,
com.acme.shared.osgi,
com.acme.utilities

em>应该是这样的:

  Bundle-ClassPath:lib / jena.jar,
。 ,
lib / google-collect-snapshot.jar
Import-Package:com.acme.client.translation,
com.acme.client.translation.interfaces,
com。 acme.shared.osgi,
com.acme.utilities,
org.apache.log4j

关键的区别是log4j被用作一个包,当它应该被用作一个包。 (我在我的lib目录中有一个log4j jar,当时我希望Log4j能够与OSGi正常工作)。jar 的工作原理。它显然发现了一些eclipse级的log4j配置,并利用了这一点。由于它只是一个jar(而不是一个bundle),它没有使用可以指定自定义日志记录配置的任何片段,这导致我们必须发生的其他事情:



我需要设置一个bundle片段来指定日志记录配置。 此链接来自 VonC 给了我这样做的信息。不幸的是,包含不正确的MANIFEST.MF的软件包仍然在Bundle-ClassPath中指定了log4j jar,并且似乎覆盖了Import-Package列表。



我终于弄清楚当我需要登录另一个软件包时,发生了什么事情(我刚才放弃了这一点,并且回到了在Warn级别和更高版本上使用日志。)这个新的软件包可以找不到记录配置! (所以我在同一个OSGi环境中运行了三个bundle,每个bundle都有不同的log4j行为 - 一个使用我的片段设置,另一个使用一些随机的Eclipse日志设置,最后是没有任何日志记录配置的新的bundle)这三个包的详细比较揭示了Manifest.MF文件的差异,现在他们都使用片段捆绑。



我欠一个巨大的 Eclipse Zone 的许多作者, VonC Ekkes ,freenode中#eclipse中的每个人都有帮助和耐心:)


I am starting to develop an Eclipse plugin (technically, an OSGi plugin) and one of the first problems I've run into is that I can't seem to control the commons-logging output as I normally would.

I've included the commons-logging package in the plugin dependencies, and indeed, when I log something (at INFO or higher severity) it is logged to the console. However, I can't seem to log at any lower level (such as DEBUG or TRACE).

I have specified a log4j.properties file, and it is on the classpath (for the runtime, just as the commons-logging package is) but none of the settings in that properties file have any impact on the behavior of the logger.

Here's the log4j.properties file:

#  Log4j Logging levels, in order of decreasing importance are:
#   FATAL, ERROR, WARN, INFO, DEBUG, TRACE
#

# Root logger option
log4j.rootLogger=ERROR,stdout
#,LOGFILE

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %r (%l) %t%n - %m%n

What do I need to do so that I can actually control the output of the logger?

Here are some sample output messages, in the hopes that the formatting may coincide with a default for java.util.logging, or provide other hints to someone:

Oct 21, 2008 11:01:23 PM com.stottlerhenke.sentinel.client.Activator start
SEVERE: fatal_message
Oct 21, 2008 11:01:23 PM com.stottlerhenke.sentinel.client.Activator start
WARNING: warn_message
Oct 21, 2008 11:01:23 PM com.stottlerhenke.sentinel.client.Activator start
INFO: info_message

Update:

I have now tried various combinations of:

and I can only get DEBUG, or lower, level messages to appear if I am running OSGi manually from a prompt (which is impractical for what I am developing). Furthermore, I can't effect any other type of logging configuration via various properties files. Everything I try in that regard seems to be overridden by an eclipse setting.

I've also tried putting various config files for the above libraries in numerous places, including as plug-in fragments attached to their respective libraries as suggested here, and still, the same result happens.

I've implemented a custom LogListener, and traced the entire path of a log message (as well as I know how, anyway) with System.out.println's, and debug messages are present right up until they are output by whatever underlying logging API I'm using, then they disappear.

解决方案

3 days later...

I found the problem! There were two things I needed to do, first off, there was a problem with one MANIFEST.MF file:

I had the following in the MANIFEST.MF for one bundle:

Bundle-ClassPath: lib/jena.jar,
 .,
 org.apache.log4j-1.2.12.jar,
 lib/google-collect-snapshot.jar
Import-Package: com.acme.client.translation,
 com.acme.translation.interfaces,
 com.acme.shared.osgi,
 com.acme.utilities

That should have been this:

Bundle-ClassPath: lib/jena.jar,
 .,
 lib/google-collect-snapshot.jar
Import-Package: com.acme.client.translation,
 com.acme.client.translation.interfaces,
 com.acme.shared.osgi,
 com.acme.utilities,
 org.apache.log4j

The key difference is that the log4j was being used as a package, when it should have been used as a bundle. (I had a log4j jar in my lib dir from when I had expected Log4j to "just work" with OSGi.) The jar does work, sort-of. It evidently found some eclipse-level log4j configuration, and made use of that. Since it was just a jar (not a bundle) it didn't make use of any fragments that could specify a custom logging config, which leads us to the other thing that had to happen:

I needed to set up a bundle fragment to specify the logging config. This link from VonC gave me the info to do that. That entailed doing a number of things, unfortunately, the package with the incorrect MANIFEST.MF still had the log4j jar specified in the Bundle-ClassPath, and that seems to override the Import-Package list.

I finally figured out what was going on when I needed to log in another bundle (I had just given up at this point, and went back to using logs at the Warn level and higher.) This new bundle couldn't find a logging config! (so then I had three bundles running in the same OSGi environment, each with different log4j behavior -- one using my fragment settings, another using some random Eclipse logging settings, and finally the new bundle that didn't have any logging config.) Detailed comparisons of these three bundles revealed the difference in the Manifest.MF files, and now they all use the fragment bundle.

I owe a huge thanks to the authors of much of Eclipse Zone, VonC, Ekkes, and everyone in #eclipse on freenode for their help and patience :)

这篇关于登录Eclipse / OSGi插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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