如何在tomcat中为Web应用程序配置外部文件夹中的log4j.properties

Azh*_*har 2 java tomcat classpath tomcat5.5 java-ee

请帮助如何处理以下方案.

当前的Web应用程序: 我已将log4j.propertes放在/WEB-INF/classeswebapp的文件夹中.

想要实现: 将log4j.properties放在外部位置并从我的Web应用程序中引用,以便我可以随时修改日志位置而无需重新构建战争.

$CATALINA_HOME/propdirwebapp1/log4j.properties $CATALINA_HOME/propdirwebapp2/log4j.properties

如果我部署了多个应用程序,请建议解决方案.如果服务器上只部署了一个应用程序,请建议解决方案

Vic*_*Vic 6

在我的情况下,web.xml我添加Log4jConfigListener并且它有效.log4jRefreshInterval这里是可选的.

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>file:/<your-path-here>/log4j.properties</param-value>
</context-param>
<context-param>
    <param-name>log4jRefreshInterval</param-name>
    <!-- Refresh log4j configuration every 5 minutes. -->
    <param-value>300000</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)