Search code examples
javajakarta-eetomcatclasspathtomcat5.5

How to configure log4j.properties in external folder for a web application in tomcat


Please help how to handle the below scenario.

Current Web app : I have placed log4j.propertes in /WEB-INF/classes folder of webapp.

Wanted to achieve : Place log4j.properties in an external location and refer from my web application, so that i can modify the log location when ever i want without re building the war.

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

If i have multiple applications deployed please suggest the solution. If only one application is deployed on server please suggest the solution


Solution

  • In my case in web.xml I added Log4jConfigListener and it worked. log4jRefreshInterval is optional here.

    <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>