Log4j changing log levels dynamically

Changing log4j log levels at run time may be required some times to log additional information to analyze production issues.

So here is the configuration for the same. This works with spring based web application. Just make sure the log4jConfigLocation value is modified appropriately. Not to forget this configuration is in the web.xml.

<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>file:${appconfig.dir}/log4j.xml</param-value>
</context-param>

<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>600000</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

Leave a Reply