I am using servlet 2.5 and i followed the instructions to set up the listeners and filters, but still my webapp complains that the configuration file cannot be found. My listener, context param,filter and filter mappings are all defined as the first values in their respective locations in my web.xml. I made sure log4j-web-2.2.jar is in my classpath as well. Are there other options to load them from a spring bean? I would like to load a different config file based on a value in catalina.properties. Can somebody please advice?
<listener>
<listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
</listener>
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>classpath:*${sys:log4j2.xml.name}</param-value>
<filter>
<filter-name>log4jServletFilter</filter-name>
<filter-class>org.apache.logging.log4j.web.Log4jServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>log4jServletFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
After a lot of fiddling, i learned that with the classpath notation we cannot use system variables. So i went with the following approach. This basically allows us to provide a different file name based on our environment. This variable has to be specified in catalina.properties.
If your config file is named log4j2.xml and is located in the WEB-INF/ directory then you don't need to specify the log4jConfiguration context parameter in your web.xml.