【问题标题】:Setting external webapp logging configuration with Jetty and log4j使用 Jetty 和 log4j 设置外部 webapp 日志配置
【发布时间】:2010-11-22 13:01:34
【问题描述】:

我有一个 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


    【解决方案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>
    

    【讨论】:

    • 类路径条目必须是目录或 jars。 log4j 将在类路径上的每个条目内查找 log4j.properties 文件。因此,如果您将 'quantel/log4j.properties' 放在类路径中,它会尝试将其视为 jar 并在其中查找 log4j.properties(这将失败)。相反,如果您将“quantel”放在类路径中,它将在该目录中查找 log4j.properties。
    【解决方案2】:

    如果您只想将日志记录级别设置为调试,请在 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

    【讨论】:

      猜你喜欢
      • 2011-07-24
      • 2011-07-11
      • 1970-01-01
      • 1970-01-01
      • 2016-10-11
      • 1970-01-01
      • 2022-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多