使用Jetty和log4j设置外部Web应用程序日志记录配置

问题描述 投票:2回答:2

我有一个打包为战争的webapp,我将其部署在Jetty(版本6.1.25)中。该Web应用程序使用log4j。我希望能够通过战争外部的配置文件(即未刻录)来配置Webapp日志记录。

[我尝试使用自定义上下文WebAppContext,该类带有一个额外的类路径属性,该属性指向我想注入到webapp类路径的log4j.properties文件,但这不起作用。

<Configure class="org.mortbay.jetty.webapp.WebAppContext">
  <Set name="contextPath">/quantel</Set>
  <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/quantel</Set>
  <Set name="extraClasspath">quantel/log4j.properties</Set>
</Configure>

我收到以下错误消息:

log4j:WARN No appenders could be found for logger (org.apache.commons.configuration.ConfigurationUtils).
log4j:WARN Please initialize the log4j system properly.

是否有可能用Jetty做到这一点?

提前感谢。

web-applications log4j classpath jetty
2个回答
1
投票

我已经调整了上面的xml配置,以将包含log4j配置文件的文件夹添加到webapp类路径,而不仅仅是添加配置文件本身。它现在正在工作,但我不清楚为什么。

我的工作配置如下:

<Configure class="org.mortbay.jetty.webapp.WebAppContext">
  <Set name="contextPath">/quantel</Set>
  <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/quantel</Set>
  <Set name="extraClasspath"><SystemProperty name="jetty.home" default="."/>/quantel</Set>
</Configure>

0
投票

如果只想将日志记录级别设置为调试,请在jvm启动参数上添加一个Java选项:

vi ${jetty.base}/start.d/start.ini:

--exec
-Dlog4j.debug

如果要在不访问WAR的情况下完全控制日志记录配置,请添加一个Java选项:

--exec
-Dlog4j.configuration=file:resources/log4j.xml

另请参见:

External log4j property file with Jetty

advanced-jetty-start

© www.soinside.com 2019 - 2024. All rights reserved.