带有Jetty的外部log4j属性文件 [英] External log4j property file with Jetty
问题描述
我要将一堆Web应用程序(在Jetty中运行)从log4j迁移到slf4j.以前,log4j可以从jetty.home/resources/log4j.properties中找到log4j.properties文件.移至slf4j后,找不到外部log4j.properties文件,并且所有内容均已记录到stderror.
I'm migrating a bunch of our webapps (run in Jetty) from log4j to slf4j. Previously, log4j would find the log4j.properties file from jetty.home/resources/log4j.properties. After moving to slf4j, the external log4j.properties file is not found and everything is getting logged to stderror.
如果我在战争中构建相同的log4j.properties文件,那么一切都会按预期进行(并且与以前一样).我究竟做错了什么?我想在jetty.home/resources中使用外部日志记录配置,而不是将其构建到战争中.
If I build the same log4j.properties file inside the war, everything works as expected (and as it did previously). What am I doing wrong? I'd like to use an external logging config in jetty.home/resources as opposed to building it into the war.
在每次Webapp战争中,我都有log4j-1.2.17
,slf4j-api-1.7.10
和活页夹slf4j-log4j12-1.7.10
.
In each webapp war, I have log4j-1.2.17
, slf4j-api-1.7.10
and the binder slf4j-log4j12-1.7.10
.
Jetty start.ini是OPTIONS=Server,jmx,resources,websocket
The Jetty start.ini is OPTIONS=Server,jmx,resources,websocket
推荐答案
我能够通过在启动脚本中添加-Dlog4j.debug
java选项来解决此问题.这样做时,我发现log4j从战争中拾取了一个log4j.properties文件,该文件已添加以进行测试.
I was able to resolve this by adding the -Dlog4j.debug
java option to the start-up script. In doing so, I found that log4j was picking up a log4j.properties file from within the war that had been added for test.
我找到的解决此问题的两个选项是删除嵌入式配置文件,或添加启动选项.我能够将模块的log4j文件移至其根目录,以便将其从Maven构建中排除.这样,它仍然可以在本地使用(用于测试),但无法内置到战争中.
The two options I found for fixing this were either remove the embedded config file, or add a start-up option. I was able to move module's log4j file to it's root so that it was excluded from the maven build. This way, it is still available locally (for test) but not built into the war.
另一个可行的选择是添加-Dlog4j.configuration=file:resources/log4j.properties
启动选项.这种方法似乎有些令人费解,但会覆盖嵌入式文件.
The other option that worked was to add -Dlog4j.configuration=file:resources/log4j.properties
to the start-up options. This approach seems a bit convoluted but will override the embedded file.
这篇关于带有Jetty的外部log4j属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!