问题描述
这是一个后续(不知何故我的 第三方对 OSGi 应用程序的依赖项) 建议一些库,例如log4j已经可以作为包使用了.
在 Eclipse Indigo 中,我在安装过程中找不到可用于 Import Package
的 log4j 包,因此我创建了一个 Plugin Project from JAR archive
来捆绑 log4j 和一个 Feature Project
在 log4j.xml 配置">发布.
This is a follow-up (somehow of my Third-party dependencies to an OSGi application) where it was suggested that some libraries e.g. log4j are already available as bundles.
In Eclipse Indigo I could not find a log4j bundle available to Import Package
as part of my installation and so I created a Plugin Project from JAR archive
to bundle log4j and also a Feature Project
to bundle the log4j.xml
configuration following this post.
说实话,我不明白为什么需要片段项目,但这个过程有效.
所以我现在的问题是:
由于 log4j.xml
作为功能 jar 的一部分在导出中交付,因此需要一些努力"才能找到它并更新调试级别,所以我想知道这确实是正确的过程?
我记得最终导出的产品会在一个容易找到的位置提供 log4j 配置,但现在(尽管日志记录有效)我担心我所做的是否确实正确.
To be honest I don't understand why the fragment project is needed but this process works.
So my question now is:
Since the log4j.xml
is delivered in the export as part of the feature jar, it requires some "effort" for someone to find it and update the debug levels, so I was wondering is this indeed the correct process?
I had in mind that the final exported product would deliver the log4j configuration in an easy to find location, but now (although the logging works) I am concerned whether what I do, is indeed correct.
这里有什么帮助吗?
推荐答案
如果你真的需要暴露文件,你可以把它放在你想要的任何地方,然后确保你的程序在启动时调用这些方法之一:
If you really need to expose the file, you could put it anywhere you want, and then make sure your program calls one of these methods at startup:
- org.apache.log4j.xml.DOMConfigurator.配置(字符串文件名)
- org.apache.log4j.PropertyConfigurator.配置(String配置文件名)
- org.apache.log4j.xml.DOMConfigurator.configure(String filename)
- org.apache.log4j.PropertyConfigurator.configure(String configFilename)
如果您想在不重新启动应用程序的情况下更改配置,请使用configureAndWatch"变体.
Or use the "configureAndWatch"-variants if you would like to make changes to the config without restarting your application.
编辑:我写如果你真的需要的话",因为我经历过部署后我永远不需要打开调试日志,因为它总是打开的!这对于我对响应时间和吞吐量有正常(但不是极端)要求的应用程序来说是可以的.记录到 UDP-appender 很快(并且不会填满磁盘).或者使用滚动文件附加程序是非常安全的,并且足够快以供我使用.在确定那些难以重现的错误时,始终提供可用的调试日志是一种救命稻草.
Edit: I write "If you really need to", because I have experienced that I never need to turn on debug-logging after deployment, because it is always turned on! This is OK for applications where I have normal (but not extreme) requirements on response-time and throughput. Logging to an UDP-appender is fast (and does not fill up the disk). Or using rolling file appender is quite safe, and fast enough for my use. Always having the debug-log available is a life-saver when nailing down those hard-to-reproduce bugs.
这篇关于在 Eclipse 4 (RCP/SWT/OSGi) 应用程序中包含 log4j 的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!